add_action('woocommerce_thankyou', 'jina_send_whatsapp_notification'); function jina_send_whatsapp_notification($order_id) { if (!$order_id) return; $order = wc_get_order($order_id); if (!$order) return; $first_name = $order->get_billing_first_name(); $phone = $order->get_billing_phone(); $total = $order->get_total(); // Format phone $phone = preg_replace('/[^0-9]/', '', $phone); if (substr($phone, 0, 2) !== "91") { $phone = "91" . $phone; } $url = "https://backend.aisensy.com/campaign/t1/api/v2/send"; $body = [ "apiKey" => "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY4Y2E4OTY5NTRjZjkzMGMzMGRiNDYzMCIsIm5hbWUiOiJKaW5hIEZhc2hpb25zIFB2dC4gTHRkLiIsImFwcE5hbWUiOiJBaVNlbnN5IiwiY2xpZW50SWQiOiI2OGIxNjM2NDM4MzdjNDBjMWM5N2I5YzUiLCJhY3RpdmVQbGFuIjoiQkFTSUNfTU9OVEhMWSIsImlhdCI6MTc3NDQzMDI0NX0.dTiata7dabWVnq0GgbV3Q3cYXfuDahWQGUI6mPjXVg0", "campaignName" => "order_confirmation_v2", "destination" => $phone, "userName" => $first_name, "templateParams" => [ $first_name, (string)$order_id, (string)$total ] ]; $response = wp_remote_post($url, [ 'headers' => [ 'Content-Type' => 'application/json' ], 'body' => json_encode($body), 'method' => 'POST', 'timeout' => 20 ]); // Prevent crash if (is_wp_error($response)) { error_log("WhatsApp Error: " . $response->get_error_message()); } }