In Woocommerce, I am trying to hide the checkout postcode field if a specific city field is selected. I found a working code that hides the billing phone if company field is empty:
add_action( 'woocommerce_after_checkout_form', 'conditionally_hide_show_checkout_field', 9999 );
function conditionally_hide_show_checkout_field() {
wc_enqueue_js( "
jQuery('#billing_company').keyup(function() {
if (jQuery(this).val().length == 0) {
jQuery('#billing_phone').hide();
} else {
jQuery('#billing_phone').show();
}
}).keyup();
");
}
I don’t know how to alter this code to make the required postcode field to be hidden when a specific billing city is selected. Any help is appreciated.
2
Answers
You can do it like this:
It’s a bit much more complicated and you will need to define the city in the last function.
The following code handles multiple necessary tasks to show / hide the postcode field based on a specific defined selected city:
Code goes in functions.php file of your active child theme (or active theme). Tested and works.
Some related answers:
Hidding billing and shipping postcode on load:
Replace:
by: