如何获得woocommerce国家选择下拉列表? [英] How to get woocommerce country select dropdown?
本文介绍了如何获得woocommerce国家选择下拉列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想显示woocommerce国家/地区在网站上列出的一些位置。我怎样才能像这样获得国家列表?
I want to display woocommerce countries list some where on website. how can i get the country list like this as image?
推荐答案
是的,您可以通过在任何需要的地方使用以下代码来实现此目的
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
让我知道这对您是否也有用。
Let me know if this works for you too.
这篇关于如何获得woocommerce国家选择下拉列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文