How to Limit the Number of Digits for Zip Code Field in WooCommerce Checkout WordPress
Вставка
- Опубліковано 25 сер 2024
- In this woocommerce tutorial for beginners you will learn how to limit the numbers of digit for zip codes field in woocommerce checkout page using custom php snippet in wordpress website. So after adding code user can not exceed our restriction on zip code field.
* Use below custom code to restrict fields:
function wtwh_wc_custom_billing_fields( $fields ) {
// restricting the number of allowed digits to 5 for the billing postcode field
$fields['billing_postcode']['maxlength'] = 5;
return $fields;
}
add_filter( 'woocommerce_billing_fields', 'wtwh_wc_custom_billing_fields' );
function wtwh_wc_custom_shipping_fields( $fields ) {
// restricting the number of allowed digits to 5 for the shipping postcode field
$fields['shipping_postcode']['maxlength'] = 5;
return $fields;
}
add_filter( 'woocommerce_shipping_fields', 'wtwh_wc_custom_shipping_fields' );
* In code you see maximum length 5, so you can add number according to your requirement.
#woocommerce #field #zipcode #digit #number #billing #shipping #postalcode #wordpress #wordpresstutorial #wordpresstutorialforbeginners #webtaskwithhassan #hassangilani