=== SendApp – WhatsApp Notifications for WooCommerce & more ===
Contributors: sendapp
Tags: whatsapp, woocommerce, notifications, chat, automation
Requires at least: 6.0
Tested up to: 7.0
Requires PHP: 7.4
Stable tag: 2.1.2
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Send WhatsApp Business notifications from WooCommerce, WPForms, Elementor Pro and 25+ other plugins through the SendApp API.

== Description ==

**Turn every WordPress event into an instant WhatsApp message.** SendApp connects your website to the official SendApp WhatsApp Business API and automatically sends approved WhatsApp template messages when something happens on your site — a WooCommerce order changes status, a cart is abandoned, a form is submitted, a booking is confirmed, a subscription renews, a course is completed, and much more.

WhatsApp is the most used messaging app in the world, with message open rates far higher than email or SMS. Reach your customers where they actually read.

[Demo](https://sendapp.live/) | [What is SendApp?](https://sendapp.live/en/whatsapp-api/) | [Support](https://sendapp.live/en/contact/)

**With SendApp you can:**

* 🛒 **Recover abandoned carts** — automatically remind customers on WhatsApp to complete their purchase
* 💬 **Send WooCommerce order notifications** — order confirmed, processing, completed, shipped… straight to the customer's WhatsApp
* 🔔 **Notify your business** — get an alert on your own WhatsApp number when an order or event happens
* 💬 **Add a floating WhatsApp chat button** — let visitors start a chat with a single tap
* 🧩 **Connect 25+ plugins** — WooCommerce, WPForms, Elementor Pro, LMS, memberships, bookings, marketplaces, CRM and more
* 🌍 **Send multilingual messages** — localized in 6 languages (en, de, es, fr, it, pt)

**Why merchants choose SendApp**

* Reach message open rates far higher than email or SMS
* Recover lost revenue from abandoned carts
* Communicate directly and instantly on the channel your customers prefer
* No account activation fees
* Ready in minutes — connect your account and start sending

🛒 **Abandoned cart recovery**
When a customer adds products to the cart but doesn't check out, SendApp tags the cart as abandoned after a configurable wait time and sends an automatic WhatsApp reminder — with a checkout link — to help them complete the order.

💬 **WooCommerce order notifications**
Send automatic WhatsApp updates on every order status change, to the customer and/or to your own business phone, with an optional delay (e.g. X days after a status). Every message can include your store name, the order number, tracking info and a support contact.

🧩 **Works with 25+ plugins (SendApp → Events)**
Each integration activates automatically only when its host plugin is installed — no errors, no overhead:

* **Store & subscriptions:** WooCommerce, WooCommerce Subscriptions, WooCommerce Bookings, Easy Digital Downloads
* **Forms:** WPForms, Elementor Pro, Contact Form 7, Gravity Forms, Fluent Forms, Forminator
* **Learning & memberships:** LearnDash, LifterLMS, Tutor LMS, MemberPress, Paid Memberships Pro
* **Bookings & events:** Amelia, Bookly, Booknetic, Salon Booking System, The Events Calendar
* **Marketplaces, CRM & community:** Dokan, WCFM, FluentCRM, Groundhogg, BuddyPress / BuddyBoss, bbPress
* **Shipping, tracking & jobs:** WooCommerce Shipment Tracking, Advanced Shipment Tracking, WP Job Manager

📝 **Form notifications (SendApp → Forms)**
Fire a WhatsApp message on form submission and map form fields to your template variables — native support for WPForms (free + Pro) and Elementor Pro Forms.

💬 **Floating WhatsApp chat widget**
Add a click-to-chat WhatsApp button to your site so visitors can reach you in one tap, or embed the SendApp Agent chat snippet.

🧪 **Test & track everything**
Validate your API and templates with the built-in Test Send card, and review every message in the structured Send Log — status, HTTP code and response — filterable and purgeable from the admin.

⚙️ **Two providers, one interface**
Choose between **SendApp Official** and **SendApp Agent** in Settings → API. Same template pipeline, same admin UI — pick per account.

**Getting started**

1. Install and activate the plugin.
2. Go to **SendApp → Settings → API** and paste your API key.
3. Configure your Triggers, Notifications, Forms and Events.
4. Send a test message and go live!

Outbound WhatsApp messages use Meta-approved WhatsApp Business templates, created from your SendApp account dashboard.

== External services ==

This plugin connects to the SendApp Business API and the SendApp Agent service to send WhatsApp messages, fetch the merchant's approved WhatsApp templates and verify API credentials. Connections happen ONLY when:

* the merchant saves API settings (key verification)
* the merchant clicks "Send Test" in Settings → General
* a configured trigger / notification / event handler fires

Endpoints contacted:

* `https://official.sendapp.cloud/api/verify` — credential verification (GET)
* `https://official.sendapp.cloud/api/templates` — list approved templates (GET, paginated)
* `https://official.sendapp.cloud/api/send/template` — send a template message (POST)
* `https://app.sendapp.ai/api/whatsapp-meta/get_templates` — Agent provider templates (GET)
* `https://app.sendapp.ai/api/whatsapp-meta/send` — Agent provider message send (POST)

Data sent: the recipient phone number, the chosen template name, the template variable values (which may include order/customer/form-submission data depending on the configured trigger), the API key (and Account Token if Agent provider).

Service terms of use:

* SendApp Official: https://sendapp.live/terms-and-conditions/
* SendApp Agent (app.sendapp.ai): https://sendapp.live/terms-and-conditions/

Privacy policy of the service: https://sendapp.live/it/privacy-policy-sendapp-whatsapp/

When the optional "SendApp Agent" widget mode is enabled, the merchant pastes a snippet from app.sendapp.ai/apps/widget/script/XXXX which loads a JavaScript chat widget from `app.sendapp.ai` directly in the front-end. The plugin extracts and stores only the URL portion (no arbitrary HTML) and enqueues it via `wp_enqueue_script()`.

When the "Send Test" card is used with a template whose header is a media (image/video/document) AND the merchant has not configured a "Header Media URL" mapping, the plugin uses a public placeholder image hosted at `https://sendapp.live/wp-content/uploads/sendapp-test.jpg` as the test media. This URL is sent as part of the template payload to the SendApp API — the plugin itself does not download it, but the SendApp / Meta endpoint may fetch it server-side at delivery time. Real production sends always use the merchant-configured media URL, never this placeholder.

== Installation ==

1. Upload the plugin folder to `/wp-content/plugins/` or install via WordPress → Plugins → Add New.
2. Activate the plugin through the "Plugins" menu in WordPress.
3. Go to **SendApp → Settings → API**, choose your provider and paste your API key (+ Account Token for the Agent provider). Click "Save Changes" — the credentials are verified live.
4. Optional: go to **SendApp → Settings → General** and use the "Test API Connection" card to validate end-to-end with a real WhatsApp template.
5. Configure your triggers under **SendApp → Triggers** (to customers) and **SendApp → Notifications** (to your business phone) for WooCommerce order status changes.
6. For form integrations, configure under **SendApp → Forms** (WPForms + Elementor).
7. For other plugin events (subscriptions, bookings, LMS, …), configure under **SendApp → Events**.

== Frequently Asked Questions ==

= Do I need a WooCommerce store? =

No. WooCommerce integrations (Triggers, Notifications, Abandoned Cart) activate only if WooCommerce is installed. Without WooCommerce you can still use Forms (WPForms / Elementor), Events (24+ plugins) and the chat widget.

= Do I need WhatsApp Business API approved templates? =

Yes. WhatsApp Cloud API (which both SendApp providers use under the hood) requires Meta-approved templates for outbound messages outside the 24-hour customer service window. Create them on the SendApp account dashboard and they'll appear in the dropdowns inside the plugin.

= Where can I see what was sent? =

**SendApp → Send Log** — every send attempt is recorded with timestamp, source, recipient, template, status, HTTP code and the first 1500 chars of the API response. Filter by status / source / recipient / template, paginate, purge old entries.

= What is "Agent" mode? =

The Agent provider (app.sendapp.ai) gives you access to additional automation features built on top of the WhatsApp Business API, including an AI chat widget you can embed from Settings → Widget Chat. Functionally interchangeable with the Official provider for transactional sends.

= How are phone numbers normalized? =

The plugin prepends the country code configured in Settings → General when a number lacks the international prefix (`+` or `00`). Numbers shorter than 6 digits are rejected (logged, no send attempted).

== Privacy ==

* No personal data is collected, stored or transmitted by the plugin to any third party other than the SendApp Business API (see "External services" above).
* The send log table (`{prefix}sendapp_send_log`) keeps a record of every send attempt for debugging and auditing. Phone numbers and template names are stored; the response body excerpt may contain reflected customer data depending on the configured template. The merchant can purge entries (all / older than 30 days / failed only) from **SendApp → Send Log**.
* When a configured trigger fires, the data sent to the SendApp API includes the customer's phone number and any template variable values resolved from the order / form / event payload (typically: name, order id, total, tracking URL).
* The plugin does NOT load any third-party tracker, analytics script or remote font.

== Screenshots ==

1. API Settings: provider switch (Official / Agent) with live credential verification
2. Test API Connection: dynamic form to send a real template with all variable types (header media, body, buttons, carousel cards)
3. Send Log: filterable list of every send attempt with status, HTTP code and response excerpt
4. Triggers and Notifications: per-order-status configuration with template variable mapping

== Changelog ==

= 2.1.2 =
* Updated the plugin display name for clarity. No functional change.

= 2.1.1 =
* Naming: switched the code prefix from `sendapp_` to the more distinct `sapp_` / `SAPP_` / `Sapp_` for all functions, classes, constants, options, transients, nonce actions, AJAX actions, script/style handles and menu slugs, to avoid any collision with the common word "send". No user-facing change.
* Fixed a slow external URL in the "External services" section.

= 2.1.0 =
* Naming: all internal identifiers (functions, classes, constants, option keys, transients, nonce actions, AJAX actions, script/style handles) unified under the single `sendapp_` / `SENDAPP_` / `SendApp_` prefix, replacing the previous mix of `sendappwc_`, `SENDAPP_WC_` and `SendAppWC_`. Existing settings are migrated automatically on upgrade.
* WooCommerce is no longer a hard requirement: the `Requires Plugins: woocommerce` header was removed, since Forms, Events and the chat widget work without WooCommerce.

= 2.0.3 =
* Compliance: removed all heredoc and nowdoc syntax flagged by Plugin Check — the inline admin JavaScript blocks passed to `sendappwc_inline_js()` are now standard quoted strings with identical runtime output. No functional change.

= 2.0.2 =
* Security & WordPress.org guidelines: nonces wrapped in `sanitize_text_field(wp_unslash(...))`; all `$_POST['variable_mapping']` arrays sanitized deeply before JSON-encoding; test-send JSON values sanitized after decode.
* Compliance: replaced every inline `<style>`/`<script>` block in admin pages with `wp_add_inline_style()` / `wp_add_inline_script()` via centralized handles. Agent widget snippet now loaded through `wp_enqueue_script()` instead of an echoed `<script src>` tag.
* Cleanup: removed redundant `file_put_contents` debug log in plugin folder (relies on `WP_DEBUG_LOG`); removed `load_plugin_textdomain` (WordPress 4.6+ auto-loads .org translations); moved admin menu position from 25 to 58 to avoid conflict with core Comments slot; ABSPATH guard added to admin-dashboard-page.php; `the_content` filter now `esc_attr()`-escapes the WhatsApp wa.me URL message; updated Privacy / Terms URLs in readme.txt.

= 2.0.1 =
* New integration: Salon Booking System (free) — booking created / confirmed / paid / cancelled events with customer name, phone, email, service(s) and start/end context.

= 2.0.0 =
* Major: generic event-driven architecture (`wp_sendapp_event_triggers` table + dispatcher + registry).
* 24+ new integrations (Tier 1-4): WC Subscriptions, Contact Form 7, Gravity Forms, Fluent Forms, Forminator, LearnDash, LifterLMS, Tutor LMS, MemberPress, PMPro, EDD, WP Job Manager, Dokan, WCFM, FluentCRM, Groundhogg, BuddyPress, bbPress, The Events Calendar, WC Bookings, Amelia, Bookly, Booknetic, WC Shipment Tracking, Advanced Shipment Tracking, ACF (context extender).
* New admin page SendApp → Events with auto-discovered event types and `ctx:<key>` mapping.

= 1.5.0 =
* New form integrations: WPForms (free + Pro) and Elementor Pro Forms with field-to-variable mapping. New `wp_sendapp_form_triggers` table and SendApp → Forms admin.

= 1.4.3 =
* Widget mode switch in Settings → Widget Chat: built-in floating button OR SendApp Agent snippet (XSS-safe URL extraction).

= 1.4.2 =
* Test card now surfaces the real Meta API error message (HTTP code + decoded message) instead of "check the log".
* FLOW button support: auto-generated `flow_token` for templates with WhatsApp Flow buttons.

= 1.4.1 =
* Test card dynamic form for media URL, body / header / button URL variables and carousel cards.

= 1.4.0 =
* New SendApp → Send Log admin page with structured logging of every send attempt.

= 1.3.x =
* SendApp Agent provider support (api/whatsapp-meta endpoints) with provider-aware verify / templates / send.

= 1.2.x =
* Send delay (X days after order status) for both Triggers and Notifications via Action Scheduler.

= 1.1.x =
* Abandoned cart trigger.
* Carousel template support, button URL variable mapping, header media URL injection.

= 1.0.0 =
* Initial release: WooCommerce Triggers + Notifications, settings + chat widget, 6 locales.

== Upgrade Notice ==

= 2.0.0 =
Major release — adds 24+ plugin integrations through a new generic event-driven architecture. DB upgrade is automatic and backward-compatible. No action required on existing Triggers / Notifications.
