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        Get CustomizeWoo.com FREE
* @sourcecode    https://businessbloomer.com/?p=20203
* @author        Rodolfo Melogli
* @testedwith    WooCommerce 3.5.3
* @community     https://businessbloomer.com/club/
*/

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        Get CustomizeWoo.com FREE
* @sourcecode    https://businessbloomer.com/?p=20203
* @author        Rodolfo Melogli
* @testedwith    WooCommerce 3.5.3
* @community     https://businessbloomer.com/club/
*/

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 custom code?

You should place custom PHP in functions.php and custom CSS in style.css of your child theme: where to place WooCommerce customization?

This code still works, unless you report otherwise. To exclude conflicts, temporarily switch to the Storefront theme, disable all plugins except WooCommerce, and test the snippet again: WooCommerce troubleshooting 101

Related content

  • WooCommerce: Add “Confirm Email Address” Field @ Checkout
    A correct email address is worth a thousand dollars, some ecommerce expert would say 🙂 So, you don’t want your WooCommerce checkout visitors to mess up with that, do you? What about adding an “Email Verification” field? In this way, we can make sure they double check their entry – and also show an error […]
  • WooCommerce: Hide Checkout Fields if Virtual Product @ Cart
    If you sell downloadable/virtual products and need to simplify your WooCommerce checkout when such product type is in the Cart, you’ve come to the right place! Here’s a simple snippet, as well as a handy mini-plugin, that checks if there are only “virtual” products in the Cart and hides all the billing fields and order […]
  • WooCommerce: How to Add a Custom Checkout Field
    Let’s imagine you want to add a custom checkout field (and not an additional billing or shipping field) on the WooCommerce Checkout page. For example, it might be a customer licence number – this has got nothing to do with billing and nothing to do with shipping. Ideally, this custom field could show above the […]
  • WooCommerce: Move / Reorder Checkout Fields (Email, Country, etc.)
    We’ve already seen how to disable fields on the checkout page by using a simple snippet. Given my ultimate goal of trying to do as much as possible without installing heavy-weight plugins, today we’ll take a look at how to move fields around inside the billing & shipping sections.
  • WooCommerce: Add House Number Field @ Checkout
    A North European client told me they’re really strict about billing and shipping addresses over there. Couriers usually require a separate “House Number” in order to dispatch packages within those countries. This must be therefore placed on the checkout, BESIDE the “Address_1” field and made required. Also, it’s a good idea to make this show […]

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent 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. Follow @rmelogli

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

  1. Hi Rodolfo. Love your code snippets!
    However in this case, you are making the field not mandatory – it becomes optional with your code. I guess by definition, if it’s optional then there’s no validation.
    But if you want to keep the field as mandatory but remove the validation of the post code (so you can add any text in there) then I suggest the following:

    unset($address_fields['postcode']['validate']);
    
    1. Nice!

  2. Greetings Rodolfo,

    First off, great work with all the information and snippets you provide. They’ve proven to be very usefull in the past allready!
    I’ve tried your snippet to disable address validation but can’t seem to get it to work. Our client sells to customers in France and it’s custom there to write the housenumber in front of the street name, eg. “1 Place general”. Woocommerce triggers a validation error on this. using your code provided, I’ve used the snippet below but this doesn’t seem to work. Do you have any further advice for this perhaps?

    1. Hey Nikolaj, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  3. 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

  4. 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?

  5. 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 🙂

  6. 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.

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

  8. 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 🙂

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

  10. 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 🙂

  11. 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?

  12. 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;
      
      
  13. 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? Customization? Leave your comment now!
_____

If you are writing code, please wrap it like so: [php]code_here[/php]. Failure to complying with this, as well as going off topic or not using the English language will result in comment disapproval. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining the Business Bloomer Club to get quick WooCommerce support. Thank you!

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