【发布时间】:2015-06-25 09:55:05
【问题描述】:
我想在网站的某些位置显示 woocommerce 国家/地区列表。我怎样才能得到这样的国家列表作为图像?
【问题讨论】:
标签: wordpress woocommerce e-commerce
我想在网站的某些位置显示 woocommerce 国家/地区列表。我怎样才能得到这样的国家列表作为图像?
【问题讨论】:
标签: wordpress woocommerce e-commerce
是的,你可以通过在任何你想要的地方使用以下代码来实现这一点
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>';
我已经测试过相同的代码,并在简码中使用了相同的代码,并在产品描述中使用了该简码
让我知道这是否也适合你。
【讨论】:
woocommerce_form_field 有一个 type => country 参数,这个参数确实准确,你在找什么.. 见 Braj Kishor Sah 的回答..
这里是非常简单和缩小的代码:
global $woocommerce;
woocommerce_form_field( 'billing_country', array( 'type' => 'country' ) );
【讨论】:
woocommerce_form_field 函数是here
如果您想要自定义国家/地区,可以将其添加到您的 function.php 中:
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;
}
【讨论】: