Auto-Subscribe WooCommerce Customers
Automatically add WooCommerce customers to SMS groups after purchase.
Automatically enroll WooCommerce customers in SMS subscriber groups after they complete a purchase.
For Block-Based Checkout (WooCommerce 8.3+)
Use this code for the new Gutenberg checkout block:
add_action('woocommerce_store_api_checkout_order_processed', function (WC_Order $order) {
$mobileNumber = \WP_SMS\Helper::getWooCommerceCustomerNumberByOrderId($order->get_id());
\WP_SMS\Newsletter::addSubscriber(
$order->get_billing_first_name(),
$mobileNumber,
'2' // Replace with your Group ID
);
});
For Classic Checkout
Use this code for the traditional checkout form:
add_action('woocommerce_checkout_order_processed', function ($orderId, $postedData, WC_Order $order) {
$mobileNumber = \WP_SMS\Helper::getWooCommerceCustomerNumberByOrderId($orderId);
\WP_SMS\Newsletter::addSubscriber(
$order->get_billing_first_name(),
$mobileNumber,
'2' // Replace with your Group ID
);
}, 10, 3);
Configuration
- Add the code to your theme’s
functions.phpor a custom plugin - Replace
'2'with your actual group ID from SMS → Groups - Test with a sample purchase
Helper Functions
| Function | Description |
|---|---|
getWooCommerceCustomerNumberByOrderId() | Retrieves customer phone number from order |
addSubscriber() | Enrolls customer in specified SMS group |
Use Cases
- Add customers to a “Customers” group for order updates
- Segment by product category for targeted promotions
- Build loyalty program subscriber lists
Related
- Auto-Subscribe on Registration - Subscribe users on registration
- WooCommerce Gutenberg Checkout - Block checkout integration
- Manage Groups - Create subscriber groups
Last updated: December 28, 2025