Platform
Chatbot Builder Bulk Messaging Team Inbox Mini CRM API & Webhooks AI Integration WhatsApp Flows
Industries
E-commerce & D2C Real Estate Education Healthcare Finance & BFSI Logistics Hospitality Retail
Integrations 📚 Learn 🗂 Codex Compare Pricing About Contact Start Free Trial →
Technical Guide Step-by-Step ⏱ 15 min read

Connect WordPress to WhatsApp API — Hooks, REST API & Plugin Methods

WordPress powers 43% of the web — and most Indian business websites. Whether you're running a WooCommerce store, a service business, or a lead-gen site, this guide shows you exactly how to send WhatsApp from WordPress events — form submissions, order placed, user registration, post published — using WP hooks, the REST API, and plugin integrations.

Get WA.Expert API Key → Talk to a Developer

What this guide covers

WordPress's hook system (actions and filters) is the cleanest integration point. Every meaningful event in WordPress fires an action hook — you attach a function to that hook, and it calls WA.Expert API. No plugin needed. For non-developers, several WordPress plugins provide a visual interface.

Integration approachComplexityBest for
WP Action Hooks + functions.php⭐⭐ Medium — PHP knowledgeMost direct. Add code to theme's functions.php or a custom plugin.
WP REST API endpoint trigger⭐⭐ Medium — REST API knowledgeExternal trigger via WordPress REST API → your custom endpoint → WA.Expert.
Contact Form 7 / Gravity Forms hook⭐ Easy — form plugin + PHP snippetFire WhatsApp on any CF7 or Gravity Form submission.
WooCommerce order hooks⭐ Easy — WooCommerce + PHP snippetWooCommerce order status changes → WhatsApp. Most popular WP use case.
Plugin (WA.Expert WP plugin)⭐ Easy — no codeInstall WA.Expert WordPress plugin — no PHP needed.

How to connect — all methods explained

Method 1 WooCommerce Order Hooks — Most Popular

1

Add code to functions.php or custom plugin

Open Appearance → Theme File Editor → functions.php (or create a custom plugin for better practice). All WooCommerce + WhatsApp code goes here.

2

Hook into WooCommerce order status changes

Use add_action("woocommerce_order_status_{status}", $callback, 10, 2). Replace {status} with: processing (payment received), completed (order fulfilled), or shipped (custom status). The callback receives $order_id and $order.

3

Get customer phone from order

Use $order = wc_get_order($order_id). Then $phone = $order->get_billing_phone(). This gets the phone number entered at checkout. WA.Expert normalises Indian formats automatically.

4

Call WA.Expert API via wp_remote_post

Use WordPress's built-in wp_remote_post() function — safer than raw cURL in WP. Pass the WA.Expert API endpoint, headers, and JSON body. Check wp_is_wp_error() on the response.

5

Test with a sandbox order

Place a test order in WooCommerce (use WooCommerce's Test Mode). Check your phone for the WhatsApp. Check PHP error log for any issues (wp-content/debug.log if WP_DEBUG_LOG is enabled).

// WordPress functions.php // WooCommerce: WhatsApp on payment received add_action('woocommerce_order_status_processing', function($order_id) { $order = wc_get_order($order_id); $phone = $order->get_billing_phone(); $name = $order->get_billing_first_name(); $total = $order->get_total(); $num = $order->get_order_number(); if (!$phone) return; wp_remote_post('https://api.wa.expert/v1/send', [ 'headers' => [ 'Authorization' => 'Bearer YOUR_API_KEY', 'Content-Type' => 'application/json', ], 'body' => json_encode([ 'to' => $phone, 'template' => 'wc_order_confirm', 'variables'=> ['name'=>$name, 'order'=>$num, 'total'=>$total], ]), 'timeout' => 15, ]); }, 10, 1 );

Use a custom plugin (not functions.php) for production code — theme updates will overwrite functions.php. Create a file wp-content/plugins/waexpert-integration/waexpert-integration.php with the plugin header comment and your hooks.

Method 2 Contact Form 7 + WhatsApp

1

Add hook after CF7 submission

Use wpcf7_mail_sent action — fires every time a CF7 form is submitted successfully. Hook: add_action("wpcf7_mail_sent", $callback).

2

Access form data

In callback: $submission = WPCF7_Submission::get_instance(). $data = $submission->get_posted_data(). Access fields by name: $data["your-phone"], $data["your-name"], $data["your-message"].

3

Add a phone field to your CF7 form

In CF7 form editor: add [tel your-phone] field with acceptance validation. This collects the phone for WhatsApp. Label it "WhatsApp Number" to increase fill rate.

4

Call WA.Expert API

Same wp_remote_post() approach as WooCommerce. Map form fields to WhatsApp template variables.

// WordPress: Contact Form 7 → WhatsApp add_action('wpcf7_mail_sent', function($cf7) { $sub = WPCF7_Submission::get_instance(); $data = $sub->get_posted_data(); $phone = $data['your-phone'] ?? ''; $name = $data['your-name'] ?? ''; if (!$phone) return; wp_remote_post('https://api.wa.expert/v1/send', [ 'headers' => ['Authorization'=>'Bearer YOUR_KEY', 'Content-Type'=>'application/json'], 'body' => json_encode([ 'to' => $phone, 'template' => 'cf7_confirmation', 'variables'=> ['name' => $name], ]), ]); });

Common questions

Which WordPress hooks fire for which events?
Key WordPress + WooCommerce hooks for WhatsApp: wpcf7_mail_sent (Contact Form 7 submit), gform_after_submission (Gravity Forms), woocommerce_order_status_processing (payment received), woocommerce_order_status_completed (order fulfilled), user_register (new WP user), comment_post (new comment), publish_post (post published). Each passes relevant data to your callback function.
Should I put WhatsApp code in functions.php or a custom plugin?
Always use a custom plugin for production code — functions.php is overwritten when you update your theme. Create a minimal plugin: wp-content/plugins/waexpert-hooks/waexpert-hooks.php with a plugin header and your add_action() calls. This survives theme updates and can be activated/deactivated independently.
How do I handle errors when WA.Expert API is unavailable?
wp_remote_post() returns a WP_Error object on connection failure. Always check: if (!is_wp_error($response)) { process success } else { log_error }. Use error_log() to log failures to the PHP error log. Consider a retry queue using WP cron (wp_schedule_single_event) for critical notifications.
Can I trigger WhatsApp from Gravity Forms?
Yes — Gravity Forms uses the gform_after_submission hook. It passes $entry (form data) and $form (form definition). Access fields by ID: $entry["1"] for field ID 1. Map the phone field (add a Phone field type in GF) to the WA.Expert "to" parameter.
Does this work with WordPress.com (hosted)?
WordPress.com does not allow custom PHP code or custom plugins. This integration requires self-hosted WordPress (WordPress.org) where you have access to the file system and can add code to plugins or functions.php. For WordPress.com, use Zapier's WordPress integration (requires Business plan) as a workaround.
How do I store API keys securely in WordPress?
Never hardcode API keys in functions.php. Use WordPress options: add_option("waexpert_api_key", "YOUR_KEY") via Settings page, or define("WAEXPERT_API_KEY", "YOUR_KEY") in wp-config.php (outside web root). Access in code: get_option("waexpert_api_key") or the constant WAEXPERT_API_KEY. The wp-config.php approach is most secure.

More connection guides

Ready to connect WordPress to WhatsApp?

Three lines of PHP in your functions.php and every WooCommerce order fires a WhatsApp. Or install the WA.Expert WP plugin for zero-code setup.

Start Free Trial → Talk to a Developer