在Woocommerce中,除了结帐页…上的特定国家外,我试图取消所有国家的计费状态字段。
这是我的代码:
add_filter( 'woocommerce_checkout_fields','custom_override_default_address_fields' );
function custom_override_default_address_fields($myfields){
global $woocommerce;
$country = $woocommerce->customer->get_billing_country();
if($country !== 'US' || $country !== 'AU' || $country !== 'CA' || $country !== 'GB'){
unset( $myfields['billing']['billing_state'] );
}
return $myfields;
}但它并不是真正的…
如何删除除woocommerce中特定国家之外的所有国家的计费状态字段?
发布于 2018-04-04 15:03:45
似乎您希望删除除美国、非盟、CA和GB以外的所有国家的计费状态,因此这里是这样做的,但它将影响计费和状态字段(两者均):
add_filter( 'woocommerce_states' , 'keep_specific_country_states', 10, 1 );
function keep_specific_country_states( $states ) {
// HERE define the countries where you want to keep
$countries = array('US', 'AU', 'CA', 'GB');
$new_country_states = array();
// Loop though all country states
foreach( $states as $country_code => $country_states ){
if( ! in_array( $country_code, $countries ) ){
// Remove states from all countries except the defined ones
$states[$country_code] = array();
}
}
return $states;
}代码在您的活动子主题(或活动主题)的function.php文件中。测试和工作。
https://stackoverflow.com/questions/49648722
复制相似问题