1

Does anybody know how to disable the Postcode validation on the checkout page in WooCommerce?

I want to input 'text content' in "billing_postcode" field, but the shop says it's an invalid postcode.

Does anyone know how I can disable Postcode validation or allow text characters?

jchamp
  • 172
  • 3
  • 11
Mostafa
  • 197
  • 3
  • 18

2 Answers2

3

Just do this:

add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields', 99 );

function custom_override_checkout_fields( $fields ) {

    unset($fields['billing']['billing_postcode']['validate']);
    unset($fields['shipping']['shipping_postcode']['validate']);

    return $fields;
}

You can put this pretty much anywhere, but preferably in a custom plugin or in your theme's functions.php

Community
  • 1
  • 1
Pelmered
  • 2,727
  • 21
  • 22
  • For some reason, this doesn't work for me. I've tried hooking to `woocommerce_default_address_fields` and `woocommerce_checkout_fields`. When I remove `postcode`, WooCommerce validates it regardless. And if I just delete or set `[validate]` to false, it will still validate. – John Doe Feb 03 '19 at 15:20
1

You could try this:

add_filter( 'woocommerce_default_address_fields', 'custom_override_address_fields', 999, 1 );
function custom_override_address_fields( $address_fields ) {

    // set as not required
    $address_fields['postcode']['required'] = false;

    // remove validation
    unset( $address_fields['postcode']['validate'] );

    return $address_fields;
}
Joe
  • 129
  • 3
  • 6