'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



Solution 1:[1]

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.

Solution 2:[2]

Here is very simple and minified code:

global $woocommerce;    
woocommerce_form_field( 'billing_country', array( 'type' => 'country' ) );

Solution 3:[3]

You can add this to your function.php if you want custom country :

add_filter( 'woocommerce_checkout_fields', 'add_custom_select_country' );
function add_custom_select_country( $fields ) {
    $fields['billing']['billing_select_country'] = array(
        'type'      => 'select',
        'required'  => true,
        'clear'     => false,
        'options'   => array(
        'country'   => __('Country', 'woocommerce' ),
        'fr'        => __('France', 'woocommerce' ),
        'gb'        => __('United Kingdom', 'woocommerce' ),
        'ru'        => __('Russian', 'woocommerce' )
    )
);
return $fields;
}

Solution 4:[4]

My approach was this:

$wc_countries = new WC_Countries();
$countries = $wc_countries->get_countries();

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Domain
Solution 2 kontur
Solution 3 colapsnux
Solution 4 Davide Iandoli