在WooCommerce中将越南国家/地区的州结帐字段设为必填项 [英] Make state checkout field required for a Vietnam country in WooCommerce
问题描述
WooCommerce中的越南国家/地区尚未定义州,因此我
在结帐页面上添加了一些州。
The country of Vietnam in WooCommerce does not have defined states, so I added some states to my checkout page.
这是我的代码:
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;
}
它确实可以正常工作,但是对于越南来说是可选字段。
It do work as I would like, but it is an optional field for Vietnam.
如何根据越南的需要设置此州字段?
How to make this state field as required for Vietnam?
我们将不胜感激。
推荐答案
以下功能将使越南在woocommerce中成为必填字段:
The following function will make for Vietnam the state field as a required in 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文件中。经过测试并有效。
Code goes in functions.php file of your active child theme (active theme). Tested and works.
说明:每个国家/地区都有特定的区域设置 WooCommerce中的字段设置。我们正在添加/更改在
WC_Countries
get_country_locale()
方法
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中将越南国家/地区的州结帐字段设为必填项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!