In Woocommerce, I am trying to unset the billing state field for all countries except specific ones on checkout page…
Here is my code:
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;
}
But it doesn't work really…
How can I remove billing state field for all countries except specific ones in woocommerce?
It seems that you would like to remove billing state for all countries except for US, AU, CA and GB, so here is the way to do it, but it will affect billing and shipping state fields (both):
Code goes in function.php file of your active child theme (or active theme). Tested and work.