WodPress:woocomerce中的billing_phone必须以05开头并接受10个数字

问题描述 投票:0回答:1

我想在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' );
    }
}

我需要从结帐页面和注册页面进入

怎么做

wordpress woocommerce
1个回答
0
投票

请检查一下,希望它能起作用

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' );
    }
    }
© www.soinside.com 2019 - 2024. All rights reserved.