Does anybody know how to disable the Postcode validation on the checkout page in WooCommerce?
My country is set up as Switzerland, but I want also people from Austria and Germany allow to order.
So when I enter a German Postcode with 5 digits (in Switzerland there are only 4), the shop says it's an invalid postcode. (but in the settings I allowed every country).
Any idea how to fix that?
One option to disable the zip code validation is to completely remove the postcode field from the WooCommerce checkout page. The easiest way to do this is by using some of the WooCommerce hooks. So, to remove the zip field from the checkout page, simply copy and paste the following script at the end of the functions.php file of your child theme:
Another plugin that you can use to remove the postcode field is Direct Checkout. This is one of the best checkout plugins for WooCommerce and allows you to remove unnecessary fields to simplify the checkout page. And the best part is that it has a free version.
The Zip field is displayed in the billing form so another way to disable the validation is to customize the billing section and remove some fields from the checkout page. In the same way, you disabled the postcode field in point 1, you can do the same with any other fields.
This code will remove the validation but will leave the field so that users can still fill the zip/postcode they prefer without the error – Billing Postcode is not a valid postcode / ZIP.
Adding this code to the functions.php file should work:
function custom_override_default_address_fields( $address_fields )
{
unset( $address_fields['postcode'] );
return $address_fields;
}
EDIT:
// Hook into the checkout fields (shipping & billing)
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
// Hook into the default fields
add_filter( 'woocommerce_default_address_fields' , 'custom_override_default_address_fields' );
function custom_override_checkout_fields( $fields )
{
unset( $fields['billing']['billing_postcode'] );
unset( $fields['shipping']['shipping_postcode'] );
return $fields;
}
function custom_override_default_address_fields( $address_fields )
{
unset( $address_fields['postcode'] );
return $address_fields;
}
ANOTHER EDIT:
add_filter( 'woocommerce_default_address_fields' , 'custom_override_default_address_fields' );
function custom_override_default_address_fields( $address_fields )
{
$address_fields['postcode']['required'] = false;
return $address_fields;
}
So I didn't actually find a simple code solution for this one but I noticed that if I set
WooCommerce > Preferences > General > Geolocate address
it will work (if settings are set to "Sell to all countries", in my case)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With