Adding New Item Fields

Type: Filter
Name: td_extra_item_input_fields
Location: wp-trade/inc/TD_Filters.php

Simply define the fields and WP-Trade will do the rest for you!

Tags you can add:

  • textarea
  • select
  • input

Rules and Instructions for creating a new field:

  • Add class=”required” to the label tag to make the field required
  • Always internationalize(I18n) your strings, Ex.
    1
    sprintf( __('Something1 %s', 'wp-trade'), get_option('td_something_symbol') )
  • Don’t forget to add a name attribute to your fields. Ex.
    1
    <input name = "td_something" />
  • When defining default select tag options, use value=”empty” for the option value. Ex.
    1
    <option value = "empty">Select</option>
  • Always wrap form tags with the form-group class. Ex.
    1
    <div class="form-group">[label][form_tag]...</div>

Example Usage

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
function my_additional_input_fields(){
   
    $msg .= '
    <div class="form-group">
        <label for="td_something" class="required">'
. sprintf( __('Something1 %s', 'wp-trade'), get_option('td_currency_symbol') ) . ' ( ' . __( Td_Admin::cvf_td_get_currency_value() ) . ' ):</label><br />
        <input type = "text" class="form-control" name = "td_something" />
    </div>
    <div class="form-group">
        <label for="td_something2" class="required">'
. sprintf( __('Something2 %s', 'wp-trade'), get_option('td_currency_symbol') ) . ' ( ' . __( Td_Admin::cvf_td_get_currency_value() ) . ' ):</label><br />
        <textarea class="form-control" name = "td_something2" /></textarea>
    </div>
    <div class="form-group">
        <label class = "required">Something 3</label>
        <select class = "form-control" name = "td_something3">
            <option value = "empty">Select</option>
            <option value = "Something1">Something1</option>
            <option value = "Something2">Something2</option>
            <option value = "Something3">Something1</option>
        </select>
    </div>
    '
;
   
    echo $msg;
}
add_filter('td_extra_item_input_fields','my_additional_input_fields');

Example of Adding Item Type, Short Description and SKU fields:

You can copy paste the bellow code into your functions.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
function my_additional_input_fields(){
   
    // Add 'Type' select box to the Submit Ad and Edit Item Page
    $msg .= '
    <div class="form-group">
        <label class = "required">Type</label>
        <select class = "form-control" name = "td_type">'
. my_custom_item_type_options() . '</select>
    </div>
     <div class="form-group">
        <label class = "required">SKU</label>
        <input type = "text" class = "form-control" name = "td_sku" />
    </div>
     <div class="form-group">
        <label class = "required">Short Description</label>
        <textarea class = "form-control" name = "td_short_desc"></textarea>
    </div>
    '
;
   
    echo $msg;
}
add_filter('td_extra_item_input_fields', 'my_additional_input_fields');

function my_custom_item_type_options( $selected_option = '' ){
   
    $options_array = array(
        'sale'          =>  'For Sale',
        'looking'   =>  'Looking to buy'
    );
   
    return cvf_generate_select_options( $options_array, $selected_option, 'Select Type' );
   
}

function my_additional_admin_single_listing_fields( $admin_single_listing_fields, $item_metadata ){
   
    // Define additional fields
    $additions = array(
        'td_type'       =>  cvf_field_builder('select', 'Type', true, my_custom_item_type_options( $item_metadata['td_type'] ) ),
        'td_sku'        =>  cvf_field_builder('text', 'SKU', true, $item_metadata['td_sku'], 'Ex. 09876' ),
        'td_short_desc' =>  cvf_field_builder('textarea', 'Short Description', true, $item_metadata['td_short_desc'], 'Enter a short description about this item' ),
    );
    $admin_single_listing_fields = array_merge( $admin_single_listing_fields, $additions );
   
    return $admin_single_listing_fields;
   
}
add_filter('td_admin_single_listing_fields', 'my_additional_admin_single_listing_fields', 10, 2);

// Show our new fields on the listings page
function my_shown_listings_fields( $shown_listings_fields, $post, $post_meta, $author ) {
   
    // Add new fields
    $additions = array(
        'item_type'     => '<span class = "glyphicon glyphicon-fire"></span> ' . __('Type') . ': ' . $post_meta['td_type'],
        'item_sku'      => '<span class = "glyphicon glyphicon-fire"></span> ' . __('SKU') . ': ' . $post_meta['td_sku'],
        'td_short_desc' => '<span class = "glyphicon glyphicon-fire"></span> ' . __('Short Description') . ': ' . $post_meta['td_short_desc']
    );
   
    $shown_listings_fields = array_merge( $shown_listings_fields, $additions );
   
    return $shown_listings_fields;
   
}
add_filter('td_shown_listings_fields', 'my_shown_listings_fields', 10, 4);


Do you need help with a project? or have a new project in mind that you need help with?

Contact Me