Digit Limit in Phone Checkout
The code snippet below can be used to limit the checkout phone field in Woocommerce checkout to 10 numbers.

Edit child-theme

function.php

1
add_filter( 'woocommerce_checkout_fields', 'custom_override_checkout_fields' );
2
3
function custom_override_checkout_fields( $fields ) {
4
5
$fields['billing']['billing_phone']['maxlength'] = 10;
6
return $fields;
7
}
8
// Limit Woocommerce phone field to 10 digits number
9
add_action('woocommerce_checkout_process', 'my_custom_checkout_field_process');
10
function my_custom_checkout_field_process() {
11
global $woocommerce;
12
// Check if set, if its not set add an error. This one is only requite for companies
13
if ( ! (preg_match('/^[0-9]{10}$/D', $_POST['billing_phone'] ))){
14
wc_add_notice( "Incorrect Phone Number! Please enter valid 10 digits phone number" ,'error' );
15
}
16
}
Copied!
Notice "Incorrect Phone Number! Please enter valid 10 digits phone number" will be shown when submitting checkout information.