由于Woo 3.5.1,某些国家/地区必须使用结算状态字段,而我正试图弄清楚如何不强制使用。
这是我正在使用的代码,它无效。这似乎是一个核心变化,我不知道是否有一个新的钩子呢?
码:
add_filter( 'woocommerce_billing_fields', 'remove_mandatory_state_billing', 10, 1 );
function remove_mandatory_state_billing( $address_fields ) {
$address_fields['billing_state']['required'] = false;
return $address_fields;
}
add_filter( 'woocommerce_shipping_fields', 'remove_mandatory_state_shipping', 10, 1 );
function remove_mandatory_state_shipping( $address_fields ) {
$address_fields['shipping_state']['required'] = false;
return $address_fields;
}
很感谢任何形式的帮助。
以下代码将使Woocommerce中所有国家/地区的州字段可选:
add_filter( 'woocommerce_get_country_locale', 'custom_country_locale_state_optional', 10, 1 );
function custom_country_locale_state_optional( $locale ) {
foreach( $locale as $country_code => $state_field ) {
if( isset($locale[$country_code]['state']) ) {
$locale[$country_code]['state']['required'] = false;
}
}
return $locale;
}
代码位于活动子主题(活动主题)的function.php文件中。经过测试和工作。
相关:Make state checkout field required for a specific country in Woocommerce