How to add the selected field for verification in WooCommerce?

I add additional fields to the checkout page in WooCommerce, I added the main text fields in order, but I need a drop-down menu or select a field with several parameters, Here is what I have done so far, but somewhere I made a mistake

$fields['billing']['billing_meat'] = array(
    'label'     => __('Food options', 'woocommerce'),
'placeholder'   => _x('', 'placeholder', 'woocommerce'),
'required'  => false,
'clear'     => false
'type'  => 'select',

'options' => array(                     // array of key => value pairs for select options
            __('I eat meat', 'woocommerce') => __('I eat mate', 'woocommerce'),
            __('meat is gross', 'woocommerce') => __('meat is gross', 'woocommerce'),

Maybe I'm not correctly defining a type field?

thanks loads

+5
source share
2 answers

If this is your exact code, the problem is that you did not receive a comma after 'clear' => false.

I tested this and it works:

$fields['billing']['billing_meat'] = array(
    'label'       => __('Food options', 'woocommerce'),
    'placeholder' => _x('', 'placeholder', 'woocommerce'),
    'required'    => false,
    'clear'       => false,
    'type'        => 'select',
    'options'     => array(
        'eat-meat' => __('I eat maet', 'woocommerce' ),
        'not-meat' => __('Meat is gross', 'woocommerce' )
        )
    );

Note that I also did not use an __()array of parameters for the keys. Better not translate them.

+8
source

it works. here is my code

// Hook in
add_filter( 'woocommerce_checkout_fields' , 'dropdown' );

// Our hooked in function - $fields is passed via the filter!
function dropdown( $fields ) {
     $fields['billing']['dropdown'] = array(
        'label'     => __('dropdown', 'woocommerce'),
    'placeholder'   => _x('dropdown', 'placeholder', 'woocommerce'),
    'required'  => false,
    'class'     => array('form-row-wide'),
    'clear'     => true,
    'type'      => 'select',
     'options'     => array(
        'option 1' => __('option 1', 'woocommerce' ),
        'option 2' => __('option 2', 'woocommerce' )
        )//end of options
     );

     return $fields;
}

. , _billing_dropdown. "admin columns", ( ). " " . ? "", "_billing_purpose" = > "textarea". !

https://scontent-b-hkg.xx.fbcdn.net/hphotos-xpf1/v/t1.0-9/10696182_985415141473105_5302358697439449940_n.jpg?oh=74cb5ebc6b1ad6dd0c29e51293b61fdf&oe=5502613C

+5

All Articles