Woocommerce limit zip code to 5 characters

Can anyone help me limit the zip code field to 5 character in my WooCommerce checkout page?

I’ve tried adding MAXLENGTH to the field but that doesn’t work also tried adding script to the function.php file that seems to work on the billing address but not the Billing details zipcode field.

function my_wc_custom_billing_fields( $fields ) {
$fields[‘billing_postcode’][‘maxlength’] = 5;

return $fields;

}

add_filter( ‘woocommerce_billing_fields’, ‘my_wc_custom_billing_fields’ );

function my_wc_custom_shipping_fields( $fields ) {
$fields[‘shipping_postcode’][‘maxlength’] = 5;

return $fields;

}

add_filter( ‘woocommerce_shipping_fields’, ‘my_wc_custom_shipping_fields’ );

Hi @adgroupagency,
Thanks for reaching out.

Although it is not in the scope of our support, I would like to suggest a few articles which may be helpful to you.

  1. https://wordpressdeveloperonline.com/woocommerce-checkout-zip-code-or-pin-code-field-validation/
  2. https://rudrastyh.com/woocommerce/custom-checkout-validation.html
  3. https://webcusp.com/5-easy-steps-to-restrict-shipping-buy-pin-code-zip-codes-woocommerce/

Just to inform you, that we don’t offer any investigation or support to the custom codes or related issues.

Thanks

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.