Woocommerce and country array on checkout

I am using woocommerce 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 can’t 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 dynamically load all countries from woocommerce. I don’t 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?

Related posts

1 comment

  1. 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:

    WC()->countries->get_shipping_countries();
    WC()->countries->get_allowed_countries();
    

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

Comments are closed.