How to remove postcode validation in Woocommerce?

Woocommerce have default validation on postcode fields. Sometimes we may feel the need to remove this validation. Like if we wanted to insert a text info instead woocommerce won’t allow it and will show an error message.

In this tutorial; We will learn how to remove postcode validation on checkout page of woocommerce in billing fields as well as shipping fields.

Our team at Themelocation is comprised of WordPress developers of high expertise

  • We can maintain, support and manage your single, or all your clients, website with dedication
  • Our skills are at your disposal.

Book a Call

So, let’s proceed step by step. First of all go to a product page and add a product to cart by clicking on add to cart button.

2015-09-09_1525Click on proceed to checkout to go to the checkout page. On checkout page, you will need to add a valid postal code and if you do not enter a postcode, Woo will give you an error.

Now, we need to remove this validation. To do this add the following lines of code at the end of your theme’s functions.php file:

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

This code will remove the Postcode validation and You can proceed without it. Thanks

Waqas

I hope you enjoy reading this blog post. If you want my team to do WooCommerce Maintenance for you, click here.

1 thought on “How to remove postcode validation in Woocommerce?”

  1. Anthony Blears

    Thank you for this. For anyone else wondering how to stop the postcode being a required field, you need to use a different filter:

    add_filter( ‘woocommerce_default_address_fields’ , ‘moso_custom_override_default_address_fields’ );

    function moso_custom_override_default_address_fields( $address_fields ) {
    $address_fields[‘postcode’][‘required’] = false;
    return $address_fields;
    }

Leave a Comment

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