i am using woocomerce plugin. Idea was to edit checkout page to create my own classes , placeholders etc for fields. With some googling i managed it all. Only thing that i cant change is country dropdown/select. For example having this code

 $fields['shipping']['shipping_country'] = array(   

    'type'              => 'select',
    'label'             => 'Country',
    'placeholder'       => '',
    'maxlength'         => false,
    'required'          => false,
    'class'             => array(),
    'label_class'       => array('col-md-6'),
    'input_class'       => array('col-md-6'),
    'return'            => false,
    'options'           => array( 'Germany' => 'Germany',
    'Germany' => 'Germany'),
    'custom_attributes' => array(),
    'validate'          => array(),
    'default'           => '',


I want to dynamicly load all countries from woocomerce. I dont want to add country by country in array, dont think thats the right way also. So is there some object or whatever that will load in this 'options' array all available countries?

1 Answers

cale_b On

You aren't very specific - you haven't shared where this code exists in your system, or which countries you want, but the answer to your question is yes.

Check out these two functions:


NOTE: You ALSO probably want to be using the woocommerce_form_field for this, since it does all the heavy lifting for you.