WooCommerce - disable postcode validation

marcelgo picture marcelgo · Apr 27, 2014 · Viewed 13.4k times · Source

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.

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?

Answer

Howli picture Howli · Apr 27, 2014

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