Skip to content

E-commerce & payments

Validate phone numbers and emails in WooCommerce

Check the billing email and phone at WooCommerce checkout, classic and block, with the Qelka WordPress plugin or a small plugin of your own that fails open.

Updated 2026-11-26

This guide stops a WooCommerce order when the billing email cannot receive mail or the billing phone number does not exist, with a clear message on the checkout page. The easiest way is the Qelka plugin for WordPress. If you cannot use it yet, or want the logic in your own code, a short plugin below does the same for the classic checkout, the block Checkout and My Account registration.

The Qelka plugin

The plugin "Qelka – Email and Phone Validation" was submitted to the WordPress.org plugin directory on 2026-11-26 and is in review, so it is not installable from the directory yet. Once it is listed, you install it from the Plugins screen, paste your key in Settings > Qelka and tick the places to check. For WooCommerce it covers:

  • The classic checkout and the block-based Checkout: billing email and billing phone, with the billing country used to read numbers written without +.
  • My Account registration.
  • Rules you choose: invalid, undeliverable, disposable and role-based addresses, invalid phone numbers. A typo of a common domain gets a "Did you mean" suggestion.

It fails open: with no key, an empty balance, a refused key or a slow API, the order goes through and the admin shows a notice that names the reason. Administrators are never checked, and each answer is reused for a day. To keep the key out of the database, define it in wp-config.php with define('QELKA_API_KEY', 'sk_live_...');.

What you need

  • WordPress 6 or later on PHP 7.4 or later, and WooCommerce.
  • A Qelka API key. A sk_test_ key returns simulated results and never spends credits: see Test mode. Restrict the key to email and phone: see Restricted keys.
  • Access to wp-config.php or your server's environment variables, and the right to upload a plugin.

Steps

1. Store the key

In wp-config.php, above the line that says to stop editing, add:

php
define('QELKA_API_KEY', getenv('QELKA_API_KEY') ?: '');

Then set QELKA_API_KEY in your host's environment settings. If your host has no environment variables, put the key itself in that define. Never put it in a theme file, a database option or JavaScript. The plugin above reads the same constant, so one definition serves both.

2. The plugin

Create wp-content/plugins/checkout-validation/checkout-validation.php:

php
<?php
/**
 * Plugin Name: Checkout validation
 * Description: Checks the billing email and phone at WooCommerce checkout, classic and block, and on My Account registration.
 * Version: 1.0.0
 * Requires Plugins: woocommerce
 */

if (!defined('ABSPATH')) {
    exit;
}

if (!function_exists('signup_validation_call')) {
    function signup_validation_call(string $path, array $body): ?array
    {
        $key = defined('QELKA_API_KEY') ? QELKA_API_KEY : getenv('QELKA_API_KEY');
        if (!$key) {
            return null;
        }

        $cache_key = 'sv_' . md5($path . wp_json_encode($body));
        $cached = get_transient($cache_key);
        if (is_array($cached)) {
            return $cached;
        }

        for ($attempt = 1; $attempt <= 2; $attempt++) {
            $response = wp_remote_post('https://api.qelka.com/v1' . $path, [
                'timeout' => 5,
                'headers' => [
                    'Authorization' => 'Bearer ' . $key,
                    'Content-Type' => 'application/json',
                ],
                'body' => wp_json_encode($body),
            ]);

            if (is_wp_error($response)) {
                error_log('validation skipped: unreachable, ' . $response->get_error_message());
                return null;
            }

            $status = (int) wp_remote_retrieve_response_code($response);
            $data = json_decode(wp_remote_retrieve_body($response), true);

            if ($status === 200 && is_array($data)) {
                $kept = array_intersect_key($data, array_flip(['status', 'reason', 'did_you_mean', 'e164']));
                set_transient($cache_key, $kept, DAY_IN_SECONDS);
                return $kept;
            }

            $retry_after = (int) wp_remote_retrieve_header($response, 'retry-after');
            if ($attempt === 1 && in_array($status, [429, 500, 502, 503], true) && $retry_after <= 2) {
                sleep(max($retry_after, 1));
                continue;
            }

            $type = $data['error']['type'] ?? 'unknown';
            $request_id = wp_remote_retrieve_header($response, 'x-request-id');
            error_log("validation skipped: {$type} status={$status} request_id={$request_id}");
            return null;
        }

        return null;
    }
}

function checkout_validation_email_error(string $email): string
{
    if ($email === '') {
        return '';
    }

    $check = signup_validation_call('/email', ['email' => $email, 'mode' => 'fast']);
    if ($check === null || $check['status'] !== 'undeliverable') {
        return '';
    }

    return $check['did_you_mean']
        ? esc_html(sprintf(__('This email address cannot receive mail. Did you mean %s?', 'checkout-validation'), $check['did_you_mean']))
        : esc_html__('This email address cannot receive mail.', 'checkout-validation');
}

function checkout_validation_phone_error(string $phone, string $country): string
{
    if ($phone === '') {
        return '';
    }

    $body = ['phone' => $phone];
    if ($country !== '') {
        $body['country'] = $country;
    }

    $check = signup_validation_call('/phone', $body);
    if ($check === null || $check['status'] !== 'invalid') {
        return '';
    }

    return esc_html__('This phone number is not valid. Please check it.', 'checkout-validation');
}

function checkout_validation_classic(array $data, WP_Error $errors): void
{
    $codes = implode(' ', $errors->get_error_codes());

    if (strpos($codes, 'billing_email') === false) {
        $message = checkout_validation_email_error((string) ($data['billing_email'] ?? ''));
        if ($message !== '') {
            $errors->add('billing_email_undeliverable', $message, ['id' => 'billing_email']);
        }
    }

    if (strpos($codes, 'billing_phone') === false) {
        $message = checkout_validation_phone_error((string) ($data['billing_phone'] ?? ''), (string) ($data['billing_country'] ?? ''));
        if ($message !== '') {
            $errors->add('billing_phone_invalid', $message, ['id' => 'billing_phone']);
        }
    }
}
add_action('woocommerce_after_checkout_validation', 'checkout_validation_classic', 20, 2);

function checkout_validation_blocks($order, $request): void
{
    if ($request->get_method() !== 'POST') {
        return;
    }

    $message = checkout_validation_email_error((string) $order->get_billing_email());
    if ($message === '') {
        $message = checkout_validation_phone_error((string) $order->get_billing_phone(), (string) $order->get_billing_country());
    }

    if ($message !== '') {
        throw new \Automattic\WooCommerce\StoreApi\Exceptions\RouteException('checkout_validation_failed', $message, 400);
    }
}
add_action('woocommerce_store_api_checkout_update_order_from_request', 'checkout_validation_blocks', 20, 2);

function checkout_validation_registration($errors, $username, $email)
{
    if (is_wp_error($errors) && !$errors->has_errors()) {
        $message = checkout_validation_email_error((string) $email);
        if ($message !== '') {
            $errors->add('registration_email_undeliverable', $message);
        }
    }

    return $errors;
}
add_filter('woocommerce_registration_errors', 'checkout_validation_registration', 20, 3);

Activate it under Plugins. Do not run it next to the Qelka plugin: each would check, and spend credits, on its own.

3. How each checkout is covered

  • Classic checkout. woocommerce_after_checkout_validation passes the posted fields and a WP_Error. The code skips a field WooCommerce already rejected, such as an empty or malformed email, so no credit goes to an obvious error. The id in the error data ties the notice to the field.
  • Block Checkout. It submits through the Store API, which does not run the classic action. woocommerce_store_api_checkout_update_order_from_request receives the order and the request when the Store API writes the request into the order. It also fires on the PATCH requests the block sends while the shopper types, which is why the code only acts on POST, the place-order request. The RouteException is turned into a 400 error response, the order stays unpaid, and the block shows the message.
  • My Account registration. woocommerce_registration_errors adds the error to the registration form, and also runs when an account is created during checkout. The day-long cache means the second call costs nothing.

Test on a staging copy with both checkouts before going live.

4. Why fast mode and 5 seconds

The shopper is waiting on the Place order button. mode: 'fast' runs the syntax, DNS, disposable and role checks without asking the shopper's mail server about the mailbox, so it answers quickly and catches typos and dead domains. It never returns deliverable: when the address looks fine it says unknown with smtp_not_checked, which the code accepts. For a mailbox check, drop mode and raise the timeout to 15 seconds, as the email reference does.

5. What the plugin does with each result

Result Checkout
Email undeliverable Blocked, with did_you_mean in the message when there is one
Email risky (disposable, catch-all, full mailbox) Accepted
Email deliverable or unknown Accepted
Phone invalid Blocked
Phone unknown (no + and no billing country) Accepted
Any API failure Accepted, error type and request id in the PHP error log

To also refuse disposable addresses on My Account registration, add a branch for status risky with reason disposable in checkout_validation_registration only. Remember that this filter also runs when a shopper creates an account during checkout, so such a shopper would be stopped there too. See Block disposable email signups.

6. Test it

With a sk_test_ key, nomx@example.com returns undeliverable in fast mode and blocks the order, and any other well-formed address passes. Phone numbers are parsed for real in test mode, so a number that is too short, such as +1 415 555, is invalid. See Test mode.

Handle errors and rate limits

Nothing is billed on errors. 401 invalid_api_key, 403 forbidden and 402 insufficient_credits all end with the order accepted and a line in the PHP error log with the request id: watch that log, or you will not notice that checks stopped. A 429 or a 5xx is retried once when Retry-After is 2 seconds or less, then fails open. A key allows 200 requests per 10 seconds; a bot hammering your checkout can reach it, so keep your usual card-testing protection in front. Each email check costs 1 credit and each phone check 1. See Errors and Rate limits.

Frequently asked questions

Does this work with the block-based Checkout?
Yes. The block Checkout talks to the Store API and never runs the classic woocommerce_after_checkout_validation action, so the recipe hooks woocommerce_store_api_checkout_update_order_from_request as well and throws a RouteException, which the block shows as an error. The Qelka plugin covers both checkouts for you.
Will a slow API make my checkout slow or lose orders?
No. The recipe waits at most 5 seconds, uses the fast email mode that never contacts the shopper's mail server, and lets the order through on any timeout, outage, empty balance or key problem. Results are cached for a day, so a shopper who fixes another field and submits again does not wait twice.
Should I block disposable email addresses at checkout?
Usually not: a paying customer with a throwaway inbox is still a paying customer, and the order confirmation is the only mail you must deliver. Block only undeliverable addresses at checkout, and block disposable ones on account registration, where a lasting contact matters more.

More in E-commerce & payments

All integrations

Put this check in your product

Get an API key in under a minute. 100 free credits every month, no card required.

  • 100 free credits a month
  • No card
  • Test keys spend nothing
  • Cancel any time