- Log in to your Client Portal.
- Open WhatsApp on your phone → Linked Devices → Link a Device → Scan the QR Code.
- Copy your unique
X-API-Keyfrom Step 2 of the portal.
You don't need to edit theme core files. Use the free Code Snippets plugin:
- In your WordPress Admin, go to: Plugins → Add New.
- Search for "Code Snippets" and click Install & Activate.
- Go to Snippets → Add New, choose PHP Code, paste the code below, replace
YOUR_API_KEY_HERE, and click Save Changes & Activate.
<?php
/**
* Automated WhatsApp Notification on New WooCommerce Order
*/
add_action('woocommerce_thankyou', 'send_whatsapp_on_new_order', 10, 1);
function send_whatsapp_on_new_order($order_id) {
if (!$order_id) return;
$order = wc_get_order($order_id);
if (!$order || $order->get_meta('_wa_order_sent')) return;
$customer_name = $order->get_billing_first_name() . ' ' . $order->get_billing_last_name();
$customer_phone = $order->get_billing_phone();
$order_total = html_entity_decode(strip_tags(wc_price($order->get_total())));
$items = '';
foreach ($order->get_items() as $item) {
$items .= "- " . $item->get_name() . " (x" . $item->get_quantity() . ")\n";
}
$message = "🎉 *Order Placed Successfully!*\n\n"
. "Assalam-o-Alaikum *" . $customer_name . "*,\n"
. "Aapka order *" . $order->get_order_number() . "* receive ho gaya hai.\n\n"
. "📦 *Items:*\n" . $items . "\n"
. "💰 *Total Amount:* " . $order_total . "\n"
. "📍 *Address:* " . $order->get_billing_address_1() . ", " . $order->get_billing_city() . "\n\n"
. "Shukriya for shopping with us!";
// Send WhatsApp to Customer
send_whatsapp_gateway_api($customer_phone, $message);
// (Optional) Send Instant Alert to Store Admin / Owner
$admin_phone = '03217089084'; // Enter Admin WhatsApp Number
send_whatsapp_gateway_api($admin_phone, "🚨 *New Order #" . $order->get_order_number() . "* from " . $customer_name . " (" . $customer_phone . ") Total: " . $order_total);
$order->update_meta_data('_wa_order_sent', '1');
$order->save();
}
// Reusable WhatsApp Gateway Helper Function
function send_whatsapp_gateway_api($phone, $message) {
$apiKey = 'YOUR_API_KEY_HERE'; // ← Paste Client API Key
$apiUrl = 'https://sachalabdullah.shop/api/v1/send';
wp_remote_post($apiUrl, [
'timeout' => 15,
'headers' => [
'Content-Type' => 'application/json',
'X-API-Key' => $apiKey
],
'body' => json_encode([
'phone' => $phone,
'message' => $message
])
]);
}
Place a test order on your WooCommerce store with your personal mobile number in billing details. You will instantly receive the formatted WhatsApp confirmation message with order details!
Need Help Setting Up Your WordPress Store?
Our engineering team can assist you with custom WooCommerce hooks, OTP login, and multi-vendor alerts.