New Woo brand announcement v2 | Feb 4, 2025

Added by Mahrie - https://woomarketingstudio.wordpress.com/2024/12/20/studio-request-logo-rollout-customer-comms/

Phone Validator and Formatter

Phone Validator and Formatter allows your WooCommerce store to validate and format phone numbers seamlessly, ensuring accurate, consistent, and reliable customer contact data across all entry points.

Installation

↑ Back to top
  1. Download the .zip file from your WooCommerce account.
  2. Go toWordPress Admin > Plugins > Add New > Upload and select the ZIP file you just downloaded.
  3. Install Now and Activate the extension.

More information at: Install and Activate Plugins/Extensions.

Setup and Configuration

↑ Back to top
  1. Go to: WooCommerce > Settings > General and scroll down to the bottom section named Phone number options.
  2. Tick the checkbox to Enable the integration.
  3. Select (if you want to) the phone number country restriction (Restrict Phone Number Countries). The most used is to Match the selected Billing/Shipping country only.
  4. Select (if you want to) in which format you want to save the phone number (Standardize On Save). The most used is the E.164 format.
  5. If your developers plan to use the REST API for other validation, you can enable it here, too.

Usage

↑ Back to top
  • Checkout – both billing and shipping phones are validated and formatted. It works both for block checkout and classic checkout.
  • My Account – both billing and shipping phones are validated and formatted.
  • WooCommerce Order edit – phone numbers are formatted.
  • WordPress Profile edit – phone numbers are formatted.

Developers

↑ Back to top

For parsing, formatting, and validating international phone numbers this plugin leverages PHP library giggsey/libphonenumber-for-php based on Google’s libphonenumber library. If you want to take advantage of it in your customizations, its classes are scoped with PhoneValidatorAndFormatterDeps (eg. PhoneValidatorAndFormatterDeps\libphonenumber).

Filters

↑ Back to top

The Phone Validator and Formatter plugin provides a set of hooks (filters) to allow developers to modify its behavior according to specific requirements. Below is the list of available filters and their purpose.

Check permissions

Filter: phone_validator_and_formatter/api/check_permissions/{route}

Description: Modify the permissions required to call a specific REST API endpoint.

Parameters:

  • bool $permissions (Default: true) – Current permissions for calling the endpoint.

Allowed countries

Filter: phone_validator_and_formatter/validator/allowed_countries

Description: Modify the list of countries that allow phone number validation.

Parameters:

  • array $allowed – Current list of allowed countries.
  • string $group – The group of the phone number (billing or shipping).
  • string $country – The country selected in the address related to the phone number.

Limit countries

Filter: phone_validator_and_formatter/validator/limit_countries

Description:
Modify the country restriction settings for phone validation.

Parameters:

  • array $limit_country (Default: no_limit) – Current limit countries setting value.
  • string $group – The group of the phone number (billing or shipping).
  • string $country – The country associated with the phone number.

Functions

↑ Back to top

If you need to leverage the plugin’s functionality in your code, you can use the following functions:

functions.php content:
validator();// Get validator.
$phone_is_valid = $validator->is_valid($phone, $country, $group, $wc_validate_phone);

$phone_standardized = \phone_validator_and_formatter()->standardize($phone, $country, $format)

View on Github

REST API endpoints

↑ Back to top

If you need to leverage the plugin’s functionality in JS, you can use the following endpoints. Please enable them at first at the setting (WooCommerce > Settings > General, the setting Enable REST API):

  • for validation and standardization (POST /wp-json/phone-validator-and-formatter/v1/validate) , with the following parameters:
    • phone (string) Phone number to validate and format.
    • country (string) Country code.
    • format (string, optional) Chosen formatting (standardize_international, no_standardize, standardize_national, standardize_e164)
  • for standardization only (POST /wp-json/phone-validator-and-formatter/v1/standardize)
    • phone (string) Phone number to validate and format.
    • country (string) Country code.
    • format (string, optional) Chosen formatting (standardize_international, no_standardize, standardize_national, standardize_e164)
    • group (string, optional) Validate as billing/shipping group.

Questions and Feedback

↑ Back to top

Have a question before you buy? Please fill out this pre-sales form. Have you already purchased and need some assistance? Get in touch with us via the Help Desk.