Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get woocommerce country select dropdown?

I want to display woocommerce countries list some where on website. how can i get the country list like this as image?

enter image description here

like image 666
Jagankumar Avatar asked Jun 25 '15 09:06

Jagankumar


2 Answers

Yes you can achieve this by having the following code where ever you want

global $woocommerce;
    $countries_obj   = new WC_Countries();
    $countries   = $countries_obj->__get('countries');
    echo '<div id="my_custom_countries_field"><h2>' . __('Countries') . '</h2>';

    woocommerce_form_field('my_country_field', array(
    'type'       => 'select',
    'class'      => array( 'chzn-drop' ),
    'label'      => __('Select a country'),
    'placeholder'    => __('Enter something'),
    'options'    => $countries
    )
    );
    echo '</div>';

I have tested the same and have used the same code in a shortcode and used that shortcode on product description

enter image description here

Let me know if this works for you too.

like image 98
Domain Avatar answered Oct 21 '22 16:10

Domain


Here is very simple and minified code:

global $woocommerce;    
woocommerce_form_field( 'billing_country', array( 'type' => 'country' ) );
like image 27
Braj Kishor Sah Avatar answered Oct 21 '22 14:10

Braj Kishor Sah