WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How do I correctly get the data from a drop down (select) output into the Woocommerce Order Details section of the admin?

When I do this, I get an output for all my text box questions, but nothing for the select (dropdown).

$this->address_formats = apply_filters('woocommerce_localisation_address_formats',  array(
        'default' => "{question}\n"

function get_address_fields( $country, $type = 'billing_' ) {
$locale     = $this->get_country_locale();

$fields = array(    
    'question' => array(
    'label'       => __('Question?', 'woocommerce'),
    'placeholder' => _x('', 'placeholder', 'woocommerce'),
    'required'    => yes,
    'clear'       => yes,
    'type'        => 'select',
    'option'     => array(
        'yes' => __('yes', 'woocommerce' ),
        'no' => __('no', 'woocommerce' )


When I do this I do not get any data output in the Order details of Woocommerce

$options[] = array(
    'question' => array(
        'label'       => __('Question?', 'woocommerce'),
        'placeholder' => _x('', 'placeholder', 'woocommerce'),
        'required'    => yes,
        'clear'       => yes,
        'type'        => 'select',
        'options' => $test_array

$test_array = array(
        'no' => __('yes', 'woocommerce' ),
        'yes' => __('no', 'woocommerce' )


share|improve this question
I think we need a little bit more context than this. Where do you put this code? What do you want specifically? Where are you calling this drop down? How is the data saved (did you check the db?). – Ewout Mar 17 '13 at 12:50
The code is in the class-wc_countries.php I am new to php so I am not sure what my next step is. – user1419650 Mar 17 '13 at 13:19
Do you want to add an extra field to the checkout page with a drop-down? – Ewout Mar 17 '13 at 13:34
yes that is exactly what I am trying to do – user1419650 Mar 17 '13 at 13:37
up vote 2 down vote accepted

Take a look at the WooCommerce docs here: Tutorial – Customising checkout fields using actions and filters

your code would look something like this:

function my_custom_checkout_field( $checkout ) {

woocommerce_form_field( 'my_field_name', array(
    'type'          => 'select',
    'class'         => array('my-field-class form-row-wide'),
    'label'         => __('Question?'),
    'placeholder'       => __('Enter something'),
    'options'           => array(
        'Yes' => __('Yes', 'woocommerce' ),
        'No' => __('No', 'woocommerce' )
    ), $checkout->get_value( 'my_field_name' ));

though the input also needs processing to be displayed in the WC admin. If you have little experience with PHP, it's not that easy though. You could take a look at this plugin for inspiration.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.