• Resolved Pravin

    (@pravinlpatel)


    Why WooCommerce does not validate mobile number based on Country? My customers are from India and if someone enter less than 10 digit then WooCommerce should throw an error.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hey there, @pravinlpatel! Thanks for contacting us. I’m happy to help you.

    Thank you for your feedback. User feedback is very important to us and always appreciated, and I understand why validating the phone number would be a good idea.

    If you wish, you can submit a feature request for this here.

    In the meantime, you can see if you can find a plugin you like that can help you with that.

    You can search for “woocommerce custom checkout“, or something similar, on the Plugins > Add New section of your dashboard or on a search engine like Google, for example.

    Please note that we do not provide support for third-party plugins, so it is good to check the plugin thoroughly to see if it is reliable. You can find more about this in this guide.

    I hope this helps.

    Please let us know if there’s anything else we can do to help.

    Have a wonderful day!

    Thread Starter Pravin

    (@pravinlpatel)

    Hey, @pravinlpate!

    That’s great! Than you for contributing to the WooCommerce Community.

    I’ll mark this thread as solved, okay?

    Please feel free to reach out if there’s anything else we can help you with.

    Have a wonderful day!

    You can use this code in your child theme functions.php or Code Snippit plugin, phone number should be 10 digits starting with “05”, you can change that and the error message to what suits you.

    // 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('/^05[0-9]{8}$/', $_POST['billing_phone']);
        if ( $_POST['billing_phone'] && !$is_correct) {
            wc_add_notice( __( '<strong>Error Message !</strong>' ), 'error' );
        }
    }
    
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Mobile number validation’ is closed to new replies.