Skip to content
Connect Media Connect Media

WooCommerce SMS Notifications

Customers want to know their order was received and when it ships. With a short snippet, your WooCommerce store can send those updates by SMS through Connect Media — on any phone, no app needed.

Order #1042Shipped

What this sends

  • Processing: “we received your order” confirmation.
  • Completed: “your order is on its way”.

Setup

  1. Create a Connect Media account and generate an API key.
  2. Add define('CM_API_KEY', 'your-key'); to wp-config.php.
  3. Save the code below as wp-content/mu-plugins/cm-order-sms.php (or add it to a site-specific plugin).
  4. Place a test order with your own phone number.
<?php
/**
 * Plugin Name: Order SMS via Connect Media
 * Put CM_API_KEY in wp-config.php: define('CM_API_KEY', 'your-key');
 */
add_action('woocommerce_order_status_changed', function ($order_id, $from, $to, $order) {
    $templates = [
        'processing' => 'Hi %s, we received order #%s. We will SMS you when it ships.',
        'completed'  => 'Hi %s, order #%s is on its way. Thank you for shopping with us!',
    ];
    if (!isset($templates[$to]) || !defined('CM_API_KEY')) {
        return;
    }
    // Don't send the same status SMS twice.
    $flag = '_cm_sms_sent_' . $to;
    if ($order->get_meta($flag)) {
        return;
    }

    $phone = preg_replace('/\D/', '', $order->get_billing_phone());
    if (str_starts_with($phone, '0')) $phone = '254' . substr($phone, 1);
    if (strlen($phone) === 9)         $phone = '254' . $phone;
    if (!preg_match('/^254[17]\d{8}$/', $phone)) {
        return;
    }

    $message  = sprintf($templates[$to], $order->get_billing_first_name(), $order->get_order_number());
    $response = wp_remote_post('https://dashboard.connectmedia.co.ke/api.php', [
        'timeout' => 15,
        'headers' => ['Authorization' => 'Bearer ' . CM_API_KEY, 'Content-Type' => 'application/json'],
        'body'    => wp_json_encode(['action' => 'send', 'to' => $phone, 'message' => $message]),
    ]);
    $res = json_decode(wp_remote_retrieve_body($response), true);

    if (($res['code'] ?? '') === '201') {
        $order->update_meta_data($flag, time());
        $order->save();
    } else {
        $order->add_order_note('SMS not sent: ' . ($res['message'] ?? 'no response'));
    }
}, 10, 4);

How it works

  • Hooks into woocommerce_order_status_changed, so it fires for manual and automatic status changes.
  • Normalises the billing phone to 254XXXXXXXXX and skips invalid numbers.
  • Stores a flag on the order so the same SMS is never sent twice.
  • Adds an order note if the SMS wasn’t accepted, so your team can follow up.

Ideas to extend it

  • Add rider name and phone when an order is dispatched.
  • Send an SMS to your staff for every new order.
  • Pair with M-Pesa payment confirmations.

Need help? Our team can assist with setup — email info@connectmedia.co.ke. See also sending SMS with PHP.

Get started

Create a Connect Media account — SMS from KES 1.0, no minimum top-up, credit that never expires, and one account for Safaricom, Airtel and Telkom. Call +254 707 339 945 or email info@connectmedia.co.ke.

Frequently asked questions

Can WooCommerce send SMS to customers?

Yes. A small snippet hooked into WooCommerce order status changes can send SMS through the Connect Media API.

Will customers get duplicate SMS?

The snippet stores a flag on each order after a successful send, so the same status message isn't sent twice.

Do I need a plugin?

No separate plugin is required. Save the snippet as a must-use plugin or in a site-specific plugin.