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
| Hook | Description |
|---|---|
woocommerce_store_api_checkout_order_processed | Fires after order is processed in block checkout |
Parameters
| Parameter | Type | Description |
|---|---|---|
$order_id | int | The order ID |
$order_object | WC_Order | The order object |
$request | WP_REST_Request | The checkout request |
Related
- WooCommerce Tracking Notifications - Shipment tracking SMS
- wp_sms_send() - Send SMS function reference
Last updated: December 26, 2024