WooCommerce - disable postcode validation

14,304

Solution 1

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)

Solution 2

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;
}

Solution 3

This code only removes validation of address fields in my-account page, what you need:

add_filter( 'woocommerce_default_address_fields',
   'custom_override_default_address_fields' );

function custom_override_default_address_fields($address_fields)
{
    $address_fields['postcode']['validate'] = false;
    return $address_fields;
}

for billing and shipping:

 add_filter( 'woocommerce_checkout_fields' , 'remove_postcode_validation', 99 );

function remove_postcode_validation( $fields ) {

unset($fields['billing']['billing_postcode']['validate']);
unset($fields['shipping']['shipping_postcode']['validate']);

return $fields;
}

Also i think with removing "validate-required" class in wc-template-function.php, this feature will be deactivated (no test).

Sorry for bad English and hope this solutions solve your problem.

Share:
14,304

Related videos on Youtube

marcelgo
Author by

marcelgo

Updated on September 27, 2022

Comments

  • marcelgo
    marcelgo over 1 year

    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?

  • marcelgo
    marcelgo almost 10 years
    I added the code to the functions.php but unfortunately it still doesn't work :(
  • marcelgo
    marcelgo almost 10 years
    Nevermind :) But now I don't see any postcode field at all... It should be actually visible but I just want to be able to type in any kind of number. Sorry if my post was not clear.
  • marcelgo
    marcelgo almost 10 years
    Still saying the postcode is not valid :( Even if the field is not a mandatory field now... Maybe you have another idea ???
  • Howli
    Howli almost 10 years
    That should do it. Maybe you have some plugin that is effecting that?
  • marcelgo
    marcelgo almost 10 years
    The only Plugin I use for WooCommerce is "Min/Max Quantities" which I already deactivated. Unfortunately, still the same issue. I guess there is a kind of pattern matching defined for the postcode somewhere... Guess I have to keep trying. But thank you very much for your help so far.
  • Mr.Vibe
    Mr.Vibe almost 10 years
    The above answer removes the postcode, whereas op wants to disable the validation only. I've been looking for an answer to the same question.