<?php
// Do NOT include the opening php tag
/**
* Function to validate the length
*
*/
function wpdesk_fcf_validate_length( $field_label, $value ) {
$min_length = 3;
$max_length = 20;
$value_length = strlen( $value );
if ( $value_length < $min_length || $value_length > $max_length ) {
wc_add_notice( sprintf( '%s is not valid. The length must be between %s and %s characters.', '<strong>' . $field_label . '</strong>', $min_length, $max_length ), 'error' );
}
}
add_filter( 'flexible_checkout_fields_custom_validation', 'wpdesk_fcf_custom_validation_length' );
/**
* Add custom length validation
*
*/
function wpdesk_fcf_custom_validation_length( $custom_validation ) {
$custom_validation['length'] = array(
'label' => 'Length',
'callback' => 'wpdesk_fcf_validate_length'
);
return $custom_validation;
}
Hi, please check this filter above.
Adapt it to your needs.
That is, in your case, change the maximum character length to 5.
Once you have modified it, enter the relevant field on Checkout and enable validation.
If there are any further questions, please do not hesitate to contact me. ??
Best regards,