WooCommerce: Disable Postcode/ZIP Validation @ Checkout

An annoying thing for sellers based in Ireland (for example), is that we still don’t use post codes (they recently introduced them, but nobody’s using them). So, in today’s task, I want to show you how to disable the “REQUIRED” feature of the postcode on the checkout page.

We already saw how to completely remove the PostCode/ZIP field… but this time we wish to leave it on the checkout, and just avoid a validation error if we don’t enter anything.

Disable Postcode/ZIP Validation @ WooCommerce Checkout
Disable Postcode/ZIP Validation @ WooCommerce Checkout

PHP Snippet (Alternative #1): Disable Postcode/ZIP Validation @ WooCommerce Checkout


/**
* @snippet       Disable Postcode/ZIP Validation @ WooCommerce Checkout
* @how-to        Watch tutorial @ https://businessbloomer.com/?p=19055
* @sourcecode    https://businessbloomer.com/?p=20203
* @author        Rodolfo Melogli
* @testedwith    WooCommerce 3.5.3
* @donate $9     https://businessbloomer.com/bloomer-armada/
*/

add_filter( 'woocommerce_default_address_fields' , 'bbloomer_override_postcode_validation' );

function bbloomer_override_postcode_validation( $address_fields ) {
  $address_fields['postcode']['required'] = false;
  return $address_fields;
}

PHP Snippet (Alternative #2): Disable Postcode/ZIP Validation @ WooCommerce Checkout


/**
* @snippet       Disable Postcode/ZIP Validation @ WooCommerce Checkout
* @how-to        Watch tutorial @ https://businessbloomer.com/?p=19055
* @sourcecode    https://businessbloomer.com/?p=20203
* @author        Rodolfo Melogli
* @testedwith    WooCommerce 3.5.3
* @donate $9     https://businessbloomer.com/bloomer-armada/
*/

add_filter( 'woocommerce_checkout_fields' , 'bbloomer_alternative_override_postcode_validation' );

function bbloomer_alternative_override_postcode_validation( $fields ) {
$fields['billing']['billing_postcode']['required'] = false;
$fields['shipping']['shipping_postcode']['required'] = false;
return $fields;
}

Official Documentation

https://docs.woothemes.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/

Where to add this snippet?

You can place PHP snippets at the bottom of your child theme functions.php file (before "?>" if you have it). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such files - if you need more guidance, please take a look at my free video tutorial "Where to Place WooCommerce Customization?"

Does this snippet (still) work?

Please let me know in the comments if everything worked as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting on PHP 7+.

If you think this code saved you time & money, please join other Business Bloomer supporters and avail of 365 days of WooCommerce benefits. Thank you in advance :)

Need Help with WooCommerce Customization?

Check out these free video tutorials!

  • how-to-edit-woocommerce-with-php-snippets
  • woocommerce-hooks-add_action-list-visual
  • woocommerce-customize-single-product-page-PHP

Rodolfo Melogli

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as a WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza.

23 thoughts on “WooCommerce: Disable Postcode/ZIP Validation @ Checkout

  1. Hi!
    I have tried both of these code one by one and twist, but no changes on invalid and required. My Woocommerce version is 5.0.2 .Can you help me to solve this. Please!

    1. Hey Nur, thanks so much for your comment! I just retested this on the latest version of WooCommerce and it still works. Unfortunately this looks like custom troubleshooting work and I cannot help here via the blog comments. Thanks a lot for your understanding! ~R

  2. Hi,
    Trying to do this but getting the following error;
    Your PHP code changes were rolled back due to an error on line 1131 of file wp-content/themes/oceanwp/functions.php. Please fix and try saving again.
    syntax error, unexpected ‘add_filter’ (T_STRING), expecting function (T_FUNCTION)

    1. Hey James, thanks for your comment! I checked again and it seems there is nothing wrong with my snippets – maybe you lost a comma or something else while copying/pasting?

  3. Thanks,
    The first actually works for me.
    But the second . . . it didn’t

    Inasmuch as the first code solved the problem, I was so excited.
    Once again thanks.

    1. Great 🙂

  4. When I use either of these alternatives, it works great. However, I use calculated shipping as I ship all over the world and the shipping no longer calculates at all. Do I have to provide flat rate or free shipping for this to work properly? Does Woocommerce depend on the zip code field to use calculated shipping?

    1. Hey Sara, thanks so much for your comment! WooCommerce might depend on zip code if the shipping methods do in the settings. Other than that, you probably have some other problem (incompatible theme, error in the PHP, etc)

    2. Try completing all fields that are required. Usually is zip is optional woocommerece calculates according to another field.

  5. I’ve just tried this and added both snippets into my theme’s functions.php file worked like a charm thank you.

  6. Yes, I’m afraid it doesn’t remove the validation. It does remove the required astrick, however. Still on the hunt for the validation part of it.

    1. Ok – I added a second alternative, let me know 🙂

  7. it doesnt remove post code input, but it disable required field. Thanks for solution.

  8. I wish to totally remove the e-mail requirement and the compulsory option that is on the checkout page.I am shown that this requirement is basic for the purpose of validation but I dont need it because my site uses M-pesa mostly for purchases and the service is virtual so this requirement puts off my customers. the only requirements i need on the check out are name, country and phone number,pls assist.

    1. Hey Samuel, thanks for your comment! Unfortunately the email is the only field you can’t really remove 🙂

  9. Hi Rodolfo, I tried your snippet in my child theme functions.php file and it removed the asterisk for a required field, but I still get the validation error. I have the latest woocommerce version 2.6.14. Any ideas?

    1. Hey Jason, thanks for your comment! I tested the snippet on the same version and I didn’t get any error. What country did you select in the checkout?

  10. You have saved the day! Cheers for the snippet 🙂

    Presume this could disable required for State / County too?

    1. Glad to hear that Steve, thanks for your comment! And yes, you can do the exact same with other fields e.g.:

      
      // disable validation for State 
      
      $address_fields['state']['required'] = false;
      
      
  11. Thanks for the article, it would be better if you would update the snippet that only selected countries will make the postcode validation false. For example:

    When you select ireland, postcode validation is not required. But if you select united kingdom, postcode validation is required.

    What do you think??

    1. Thank you Jake, that’s a good idea! However, the fix you suggested is not simple at all as fields cannot be removed “dynamically” once the country is selected. It’s not a PHP-only job 🙂 I’ll think about it and see if I can come up with something hopefully. Cheers!

Questions? Feedback? Support? Leave your Comment Now!
_____

If you are writing code, please wrap it between: [php]code_here[/php]. Failure to complying with this (as well as going off topic) will result in comment deletion. You should expect a reply in about a week - this is a popular blog but I need to get paid work done first. Please consider joining #BloomerArmada to ask me 1-to-1 WooCommerce questions. Thank you :)

Your email address will not be published. Required fields are marked *