=== Bulk Order Notifications for WA - BYOK ===
Contributors: deusacc
Tags: whatsapp, woocommerce, notifications, bulk messaging, order status
Requires at least: 6.0
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 1.5.12
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Send bulk WhatsApp order and appointment notifications using your own WhatsApp Business Cloud API credentials.

== Description ==

Bulk Order Notifications for WA - BYOK connects your WordPress or WooCommerce site to the official WhatsApp Business Cloud API (Meta), so you can:

* Automatically send a WhatsApp template message when a WooCommerce order changes status (e.g. processing, completed, shipped) — map any order status to any approved WhatsApp template, and choose what fills each `{{1}}`, `{{2}}`, … placeholder: customer first name, order number, order total with currency, products, view-order link, tracking number (Shipment Tracking or `_tracking_number`) or payment method.
* Send a bulk WhatsApp notification to a list of phone numbers in one go (orders, appointments, reminders) from a simple admin screen — paste a list, pick a template, send.
* Keep a log of every message sent, with its real delivery status per recipient (sent, delivered, read, failed) reported back by Meta's webhook — paste the Webhook URL and verify token shown in Settings into your Meta app.
* Check your credentials in one click: "Send test message" sends Meta's default hello_world template to any number.

This plugin is BYOK (Bring Your Own Key): you connect your own Meta WhatsApp Business Cloud API app (Phone Number ID + Access Token). No message ever passes through a third-party server — requests go straight from your site to Meta's Graph API.

= Free vs Full version =

This free version has no sending limit: every feature above works without restrictions. [The full version](https://shop.lumnika.com/wa-bulk-notify.html) (one-time payment, no subscription) adds:

* Cash on delivery (COD) order confirmation: every new COD order goes on hold and the customer gets a WhatsApp message with Confirm / Cancel buttons; the reply moves the order to processing or cancelled, with one reminder if there's no answer. Fewer refused deliveries and return-to-origin costs.
* WooCommerce customer segments: load every customer with a paid order in the last N days, optionally only those who bought a given product, straight into the recipient list.
* Scheduled sends: queue a bulk send for a future date and time (appointment reminders, launch announcements), with a list of pending sends you can cancel — sent in rate-limited batches, so large lists don't hit Meta's throttling.
* Abandoned-cart reminders: captures the phone typed at checkout, and if no order comes in within a delay you choose, sends one WhatsApp reminder with a link that restores the cart.
* Review requests: N days after an order is completed, one WhatsApp message with a link to the product's reviews (opted-out numbers skipped).
* New-order alerts on WhatsApp to the shop owner's numbers, with the order total.
* Second abandoned-cart message with a single-use WooCommerce coupon that expires in 48 hours, applied by the link.
* CSV export of the send log.

= Requirements =

* A WhatsApp Business Account with the Cloud API enabled (Meta for Developers).
* At least one approved message template (templates with variable placeholders `{{1}}`, `{{2}}`, … are supported).
* WooCommerce, only if you want automatic notifications on order status change. The manual bulk-send screen works without WooCommerce.

== External services ==

This plugin connects to the Meta (Facebook) WhatsApp Business Cloud API (`https://graph.facebook.com`) to send WhatsApp messages on your behalf, using the Phone Number ID and Access Token you provide in Settings. Data sent: recipient phone number and the template variables you enter (e.g. customer name, order number). This happens whenever an order status you mapped changes, or when you trigger a manual bulk send or a test message. If you configure the webhook, Meta calls back your site's REST endpoint (`/wp-json/wablk/v1/webhook`) with the status of each message (message ID, status, recipient); the plugin only stores the status in its send log.

By using this plugin you agree to Meta's terms of service: https://www.whatsapp.com/legal/business-policy/ and https://developers.facebook.com/terms/

Optional setup tips: only if you tick "Send me setup tips" in the settings, the email address you enter is sent once to shop.lumnika.com (the plugin author's shop, https://shop.lumnika.com/) together with the plugin name, to send you a few setup tips by email. The box is unticked by default and nothing is sent otherwise.

== Installation ==

1. Upload the plugin files to `/wp-content/plugins/wa-bulk-notify/`, or install through the WordPress plugins screen.
2. Activate the plugin.
3. Go to Bulk Order Notifications for WA > Settings and enter your WhatsApp Business Cloud API Phone Number ID and Access Token.
4. (Optional) Map WooCommerce order statuses to approved WhatsApp templates.
5. Use Bulk Order Notifications for WA > Bulk send to send a one-off bulk notification.

== Frequently Asked Questions ==

= How does the plugin handle consent (Meta policy, GDPR)? =

Meta requires opt-in before a business messages a customer, and the GDPR requires consent in the EU. The plugin adds a WhatsApp opt-in checkbox to the checkout (classic and block) and, with "Require opt-in" on (the default), sends order updates and cart reminders only to customers who ticked it. Anyone who replies STOP is added to an opt-out list that no send can reach.

= Do I need a Meta developer account? =

Yes. You need a WhatsApp Business Account with Cloud API access, a verified phone number, and at least one approved message template. This plugin does not create that for you — it uses the credentials you already have.

= Is there a sending limit? =

No. The plugin never caps your messages; only Meta's own messaging tiers and pricing apply, billed to you directly by Meta.

= Are messages sent through your servers? =

No. Requests go directly from your WordPress site to Meta's Graph API using your own credentials.

== Screenshots ==

1. Bulk send screen — paste recipients and send a WhatsApp template to all of them.
2. Settings screen — connect your WhatsApp Business Cloud API credentials and map order statuses to templates.
3. Log screen — see delivery status for every message sent.

== Changelog ==

= 1.5.12 =
* Security: the webhook now requires the App secret; unsigned updates are rejected so nobody can fake STOP/START replies or delivery statuses. The setup checklist tells you if Meta's updates are being rejected.
* Shop managers can now open the settings, save them and send the test message (same access as Bulk send).
* Installing the full version while the free copy is active now deactivates the free copy automatically.
* Bulk send warns before you close the tab and resumes an interrupted list where it stopped, without duplicates.
* The send log keeps the last 1000 entries (was 200).

= 1.5.11 =
* Order status messages are now sent in the background (WooCommerce Action Scheduler): checkout and the order screen no longer wait for Meta.
* Failed order messages (timeout, rate limit, Meta 5xx) are retried automatically after 1, 5 and 15 minutes.
* The message log is no longer loaded on every page (autoload off).

= 1.5.10 =
* Fix: numbers already in international format (e.g. 447700900123) on orders without a billing country are no longer given the store's calling code.

= 1.5.9 =
* Customer phone numbers without a country code (e.g. 347..., 07700...) now get the calling code of the billing country, so WhatsApp delivers them and STOP/opt-in replies match the right customer.
* Optional template language per customer country (e.g. IT=it, DE=de).
* Full version: "Deactivate license on this site" frees the site slot to move the license to another site.

= 1.5.8 =
* A license key now counts the site it unlocks the full version on (3 sites per license); past the limit the full-version features turn off on that site with a clear notice and upgrade links.

= 1.5.7 =
* Declares compatibility with WooCommerce High-Performance Order Storage (HPOS): no more "incompatible plugin" warning on new stores.

= 1.5.6 =
* Without WooCommerce the Bulk Order Notifications for WA menu is now visible to administrators (manual bulk sending works without WooCommerce).

= 1.5.5 =
* After 50 and 250 order notifications sent, a dismissible notice shows what the full version adds.
* Settings: optional, unticked "Send me setup tips" email opt-in; the email is sent to shop.lumnika.com only if you tick it.

= 1.5.4 =
* After 50 sent messages, a dismissible notice on the dashboard/plugin screens invites a WordPress.org review.

= 1.5.3 =
* Settings page: links to the other BYOK plugins from Lumnika (static links, no remote calls).

= 1.5.2 =
* Full version: the license key is checked with the shop once a week; a refunded key turns the full-version features off (free features keep working).

= 1.5.1 =
* First run: activating the plugin opens the Settings page, and a Settings link sits next to Activate/Deactivate in the plugin list.

= 1.5.0 =
* Order-status templates: pick the order data for each template variable (name, order number, total, products, view-order link, tracking number, payment method). Existing mappings keep sending name + order number.
* Full version: review requests, new-order alerts to the shop owner, abandoned-cart coupon follow-up.

= 1.4.0 =
* Meta Graph API updated to v26.0 (older versions are retired by Meta about two years after release).

= 1.3.0 =
* WhatsApp opt-in checkbox at checkout (classic and block checkout), text configurable; consent saved on the order and the customer.
* "Require opt-in" (on by default): order notifications, abandoned-cart reminders and customer segments reach only opted-in numbers.
* Opt-out: replies like STOP, UNSUBSCRIBE or ANNULLA (via the webhook) add the number to an opt-out list that every send skips; START re-subscribes. The list is editable in Settings.
* Bulk sends ask you to confirm that the pasted list has opted in.

= 1.2.0 =
* Real delivery status: a Meta webhook endpoint updates each log row to sent, delivered, read or failed (with Meta's error), optionally verified with your App secret.
* Settings show a copyable Webhook URL and verify token.
* "Send test message" button to validate credentials with the hello_world template.

= 1.1.0 =
* Removed the monthly message cap: the free version is now unlimited.
* Full version: cash-on-delivery confirmation, abandoned-cart reminders, WooCommerce customer segments, scheduled sends, CSV log export.
* English menu names in the installation steps.

= 1.0.0 =
* Initial release: bulk send screen, WooCommerce order-status automation, delivery log, BYOK Meta Cloud API integration, free/full-version usage limit.

== Upgrade Notice ==

= 1.5.2 =
Full version: weekly license check.

= 1.5.1 =
Settings link in the plugin list and first-run redirect to Settings.

= 1.5.0 =
Order-status templates can now use order total, products, view-order link, tracking number and payment method.
