WooCommerce – disable postcode validation

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.

Read More

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?

Related posts

Leave a Reply

4 comments

  1. 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;
    }
    
  2. 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)

  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.

  4. The previous answers don’t seem to address the question! The postcode is still a required field, it’s matter of whether other postcodes can be allowed that WooCommerce is saying is wrong.

    For a checkout I’m building I’ve used this filter to allow any postcode to be considered valid regardless of country/postcode given.

    add_filter( 'woocommerce_validate_postcode' , 'mycode_override_postcode_check', 99, 3 );
    function mycode_override_postcode_check( $valid, $postcode, $country ) {
        return true;
    }
    

    You can change that return true; for more complex code logic that reviews the postcode and country, this can help if your version of WooCommerce doesn’t cover new postcode/zip code rules and you need them to be accepted.
    Source: https://github.com/EloxZ/wordpresscrm/blob/main/wp-content/plugins/woocommerce/includes/class-wc-validation.php#L123