WooCommerce Gutenberg Checkout

Integrate SMS validation and notifications with WooCommerce's block-based checkout.

This guide shows how to integrate SMS validation and notifications with WooCommerce’s Gutenberg-based checkout block (version 8.3+).

Prerequisites

  • WooCommerce 8.3 or later
  • WSMS plugin installed and active

Phone Number Validation

Validate phone numbers at checkout:

add_action('woocommerce_store_api_checkout_order_processed', function ($order_id, $order_object, $request) {
    $phone = $order_object->get_billing_phone();

    if (!preg_match('/^\+[1-9]\d{1,14}$/', $phone)) {
        throw new Exception('Please enter a valid international phone number.');
    }
}, 10, 3);

Send Order Confirmation SMS

Automatically send confirmation messages after checkout:

add_action('woocommerce_store_api_checkout_order_processed', function ($order_id, $order_object, $request) {
    $phone = $order_object->get_billing_phone();

    if (function_exists('wp_sms_send')) {
        wp_sms_send($phone, 'Thank you for your order! Your order ID is ' . $order_id);
    }
}, 10, 3);

Error Handling with SMS

Notify customers of processing issues:

add_action('woocommerce_store_api_checkout_order_processed', function ($order_id, $order_object, $request) {
    try {
        // Your validation logic here
    } catch (Exception $e) {
        if (function_exists('wp_sms_send')) {
            wp_sms_send($order_object->get_billing_phone(), 'Error processing your order: ' . $e->getMessage());
        }
        throw $e;
    }
}, 10, 3);

Hook Reference

HookDescription
woocommerce_store_api_checkout_order_processedFires after order is processed in block checkout

Parameters

ParameterTypeDescription
$order_idintThe order ID
$order_objectWC_OrderThe order object
$requestWP_REST_RequestThe checkout request

Last updated: December 26, 2024