Support » Plugin: WooCommerce » Limit Phone Number Digits for certain countries

  • Resolved danielmoorehbd



    I am using this code to limit phone numbers to 11 digits for DPD shipping, however, other countries outside of the UK need more digits… I can’t seem to tell the field to look out for the country and if GB then, and only then, run the rule…

    My working code so far…

    // Limit Woocommerce phone field to 11 digits number
    add_action('woocommerce_checkout_process', 'my_custom_checkout_field_process');
    function my_custom_checkout_field_process() {
        global $woocommerce;
        // Check if set, if its not set add an error. This one is only requite for companies
        if ( ! (preg_match('/^[0-9]{11}$/D', $_POST['billing_phone'] ))){
            wc_add_notice( "Please enter valid 11 digit phone number."  ,'error' );
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support thup90


    Hi there,

    You could try a plugin that helps with validating phone numbers. Here’s one that might work for your needs:

    Plugin Support Hari Shanker R


    Automattic Happiness Engineer

    Hi @danielmoorehbd

    Just checking-in on you here to see if you need help with this.

    I believe the Woo Phone Validator should be a perfect fit for your requirements.

    If you need further assistance though, feel free to hit us up in the forums.

    Since we haven’t heard from you in a while, I’m going to mark this topic as Resolved. Let us know if you keep running into troubles. You can either reply here to follow-up with the same problem, or create a new thread to report your troubles to us.

    All the best!

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.