Hi,
Add this piece of code to functions.php or use a plugin or use your own written plugin
// Set maxlength
function my_custom_override_checkout_fields( $fields ) {
$fields['billing']['billing_phone']['maxlength'] = 11;
return $fields;
}
add_filter( 'woocommerce_checkout_fields' , 'my_custom_override_checkout_fields' );
// Limit Woocommerce phone field to 11 digits number
function my_custom_checkout_field_process() {
global $woocommerce;
// Check if set, if its not set add an error. This one is only requite for companies
if ( ! (preg_match('/^[0-9]{11}$/D', $_POST['billing_phone'] ))){
wc_add_notice( "Incorrect Phone Number! Please enter valid 11 digits phone number" ,'error' );
}
}
add_action('woocommerce_checkout_process', 'my_custom_checkout_field_process');
By default WooCommerce checkout fields support the following attributes for the fields
$defaults = array(
'type' => 'text',
'label' => '',
'description' => '',
'placeholder' => '',
'maxlength' => false,
'required' => false,
'id' => $key,
'class' => array(),
'label_class' => array(),
'input_class' => array(),
'return' => false,
'options' => array(),
'custom_attributes' => array(),
'validate' => array(),
'default' => '',
);