Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WooCommerce - disable postcode validation

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?

like image 664
marcelgo Avatar asked Apr 27 '14 15:04

marcelgo


People also ask

How to disable ZIP code validation in WooCommerce checkout?

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:

How to remove postcode field from WooCommerce checkout page?

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.

How to disable the ZIP field in the billing form?

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.

Is the billing postcode not a valid postcode?

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.


2 Answers

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;
}
like image 197
Howli Avatar answered Oct 07 '22 00:10

Howli


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)

like image 36
Daniel Baur Avatar answered Oct 06 '22 23:10

Daniel Baur