Home » WooCommerce: Disable Postcode/ZIP Validation @ Checkout

WooCommerce: Disable Postcode/ZIP Validation @ Checkout

by Tutor Aspire

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 tutoraspire.com FREE
* @sourcecode    https://tutoraspire.com/?p=20203
* @author        Tutor Aspire
* @testedwith    WooCommerce 3.5.3
* @donate $9     https://www.tutoraspire.com
*/

add_filter( 'woocommerce_default_address_fields' , 'tutoraspire_override_postcode_validation' );

function tutoraspire_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 tutoraspire.com FREE
* @sourcecode    https://tutoraspire.com/?p=20203
* @author        Tutor Aspire
* @testedwith    WooCommerce 3.5.3
* @donate $9     https://www.tutoraspire.com
*/

add_filter( 'woocommerce_checkout_fields' , 'tutoraspire_alternative_override_postcode_validation' );

function tutoraspire_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/

You may also like