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

  1. Add the code to your theme’s functions.php or a custom plugin
  2. Replace '2' with your actual group ID from SMS → Groups
  3. Test with a sample purchase

Helper Functions

FunctionDescription
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

Last updated: December 28, 2025