How to get woocommerce country select dropdown?

前端 未结 3 1850
刺人心
刺人心 2021-02-10 23:05

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

3条回答
  •  迷失自我
    2021-02-10 23:51

    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 '

    ' . __('Countries') . '

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

    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.

提交回复
热议问题