• Resolved Wayn

    (@shnactor1)


    I want the user to enter a minimum of 7 numbers for their phone number in the Woocommerce checkout. The function below works but it includes spaces, so if user enter 6 numbers with 1 space it counts it as 7. How Can I change the function so that it only counts numbers not spaces so that the user has to enter a minimum of 7 numbers.

    // 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 \-]{7}/i’, $_POST[‘billing_phone’]);
    if ( $_POST[‘billing_phone’] && !$is_correct) {
    wc_add_notice( __( ‘Phone Number must be minimum 7 numbers.’ ), ‘error’ );
    }
    }

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Minimum Phone numbers digits Woocomerce Checkout’ is closed to new replies.