在 WooCommerce 中为越南国家/地区设置状态结帐字段
Make state checkout field required for a Vietnam country in WooCommerce
WooCommerce 中的越南国家没有定义的州,所以我
在我的结账页面上添加了一些州。
这是我的代码:
add_filter( 'woocommerce_states', 'vietnam_cities_woocommerce' );
function vietnam_cities_woocommerce( $states ) {
$states['VN'] = array(
'HCM' => __('Hồ Chí Minh', 'woocommerce') ,
'HANOI' => __('Hà Nội', 'woocommerce') ,
'HAIPHONG' => __('Hải Phòng', 'woocommerce') ,
);
return $states;
}
它确实如我所愿,但它是越南的可选字段。
如何根据越南要求制作此州字段?
感谢任何帮助。
以下函数将使越南成为 woocommerce 中必需的州字段:
add_filter( 'woocommerce_get_country_locale', 'custom_country_locale', 10, 1 );
function custom_default_address_fields( $locale ) {
$locale['VN']['state']['required'] = true;
return $locale;
}
代码进入您的活动子主题(活动主题)的 functions.php 文件。已测试并有效。
Explanations: Each country have specific "locale" fields settings in WooCommerce. We are adding/altering the default WooCommerce country locale settings that are defined on WC_Countries
get_country_locale()
method
WooCommerce 中的越南国家没有定义的州,所以我 在我的结账页面上添加了一些州。
这是我的代码:
add_filter( 'woocommerce_states', 'vietnam_cities_woocommerce' );
function vietnam_cities_woocommerce( $states ) {
$states['VN'] = array(
'HCM' => __('Hồ Chí Minh', 'woocommerce') ,
'HANOI' => __('Hà Nội', 'woocommerce') ,
'HAIPHONG' => __('Hải Phòng', 'woocommerce') ,
);
return $states;
}
它确实如我所愿,但它是越南的可选字段。
如何根据越南要求制作此州字段?
感谢任何帮助。
以下函数将使越南成为 woocommerce 中必需的州字段:
add_filter( 'woocommerce_get_country_locale', 'custom_country_locale', 10, 1 );
function custom_default_address_fields( $locale ) {
$locale['VN']['state']['required'] = true;
return $locale;
}
代码进入您的活动子主题(活动主题)的 functions.php 文件。已测试并有效。
Explanations: Each country have specific "locale" fields settings in WooCommerce. We are adding/altering the default WooCommerce country locale settings that are defined on
WC_Countries
get_country_locale()
method