我想在woocommerce的所有页面的电话号码(billing_phone)中添加自定义验证。我该怎么做?
// Custom validation for Billing Phone checkout field
add_action('woocommerce_checkout_process', 'custom_validate_billing_phone');
function custom_validate_billing_phone() {
$is_correct = preg_match('/^[0-9]{10}$/', $_POST['billing_phone']);
if ( $_POST['billing_phone'] && !$is_correct) {
wc_add_notice( __( 'The Phone field should be <strong>start 05 and 10 digits</strong>.' ), 'error' );
}
}
我需要从结帐页面和注册页面进入
怎么做
请检查一下,希望它能起作用
add_action('woocommerce_checkout_process', 'custom_validate_billing_phone');
function custom_validate_billing_phone() {
$is_correct = preg_match('/^05[0-9]{8}$/', $_POST['billing_phone']);
if ( $_POST['billing_phone'] && !$is_correct) {
wc_add_notice( __( 'The Phone field should be <strong>start 05 and 10 digits</strong>.' ), 'error' );
}
}