=== Premium Order Manager for WooCommerce ===
Contributors: hshhiri
Tags: woocommerce, customer management, order management, email, campaigns
Requires at least: 6.0
Tested up to: 7.0
Stable tag: 4.5.1
Requires PHP: 7.4
Requires Plugins: woocommerce
License: GPLv2 or later

Advanced WooCommerce customer & order management with SMS/email campaigns, templates, import/export, and role manager.

== Description ==

**Premium Order Manager for WooCommerce** helps you manage your WooCommerce store more efficiently.  
View customer & order stats, send bulk SMS/email campaigns using built‑in templates, import/export customer lists, convert guests to registered users, and manage user role capabilities – all from one dashboard.

== External Services ==

This plugin connects to third‑party SMS gateway APIs to send SMS messages. The following external services are used:

**SMS.ir** (https://sms.ir)  
- Used for: Sending SMS messages.  
- Data sent: Recipient phone number, message text, sender number.  
- When: When you manually send an SMS campaign or when automatic order notifications are triggered.  
- Terms of Service & Privacy Policy: https://sms.ir/terms-and-conditions/  (this page covers both terms and privacy)


**Asanak** (https://asanak.ir)  
- Used for: Sending SMS messages.  
- Data sent: Recipient phone number, message text, sender number.  
- When: When you manually send an SMS campaign or when automatic order notifications are triggered.  
- Terms of Service & Privacy Policy: https://www.asanak.com/%D9%82%D9%88%D8%A7%D9%86%DB%8C%D9%86-%D9%88-%D9%85%D9%82%D8%B1%D8%B1%D8%A7%D8%AA/ (this page covers both terms and privacy)

**IPPanel** (https://ippanel.com)  
- Used for: Sending SMS messages.  
- Data sent: Recipient phone number, message text, sender number, API token.  
- When: When you manually send an SMS campaign or when automatic order notifications are triggered.  
- Terms of Service & Privacy Policy: https://ippanel.com/ (please verify the exact terms/privacy URL on their site)

**Telegram Bot API** (https://core.telegram.org/bots/api)
- Used for: Sending campaign messages and receiving a customer's chat_id after they start a chat with your bot and share their phone number.
- Data sent: Recipient chat_id, message text, and (via your bot's webhook) the phone number a customer chooses to share with your bot.
- When: When you configure a bot token and a customer interacts with it, or when you send a Messenger campaign.
- Terms of Service & Privacy Policy: https://telegram.org/tos and https://telegram.org/privacy

**Bale Bot API** (https://tapi.bale.ai)
- Used for: Same purpose as Telegram above, via Bale's own bot platform.
- Data sent: Same as Telegram above.
- When: Same as Telegram above.
- Terms of Service & Privacy Policy: https://bale.ai/

**Eitaa Bot API** (https://eitaayar.ir)
- Used for: Same purpose as Telegram above, via Eitaa's own bot platform.
- Data sent: Same as Telegram above.
- When: Same as Telegram above.
- Terms of Service & Privacy Policy: https://eitaa.com/

**Rubika Bot API** (https://rubika.ir)
- Used for: Same purpose as Telegram above, via Rubika's own bot platform.
- Data sent: Same as Telegram above.
- When: Same as Telegram above.
- Terms of Service & Privacy Policy: https://rubika.ir/

**Meta WhatsApp Business Cloud API** (https://developers.facebook.com/docs/whatsapp)
- Used for: Sending campaign messages to a WhatsApp number you (the store admin) enter manually — this requires a Meta-verified WhatsApp Business Account and a permanent access token, which you must obtain and configure yourself.
- Data sent: Recipient phone number and message text.
- When: Only when you have configured WhatsApp Cloud API credentials and send a Messenger campaign to a WhatsApp recipient.
- Terms of Service & Privacy Policy: https://www.whatsapp.com/legal/business-terms and https://www.facebook.com/privacy/policy/

No other external services are used. The plugin does not send any data to external services unless you explicitly configure and use an SMS gateway or a messenger platform.

== Installation ==

1. Upload the `premium-order-manager-for-woocommerce` folder to `/wp-content/plugins/`, or install via the WordPress plugin repository.
2. Activate the plugin.
3. Go to **Premium Order Manager for WooCommerce** in the admin sidebar.
4. Configure SMS gateway credentials in the Settings tab.
5. Start managing customers and sending campaigns!

== Frequently Asked Questions ==

= Does this plugin work without WooCommerce? =
No. WooCommerce must be installed and activated.

= How do I send an SMS campaign? =
Go to **Premium Order Manager → Campaign**, select the SMS tab, choose recipients, write your message, and click Send SMS.

= How do I configure SMS gateways? =
Go to **Premium Order Manager → Settings**, select your gateway provider (Asanak, SMS.ir, or Appanel), and enter your API credentials.

= Are my messages logged? =
Yes, all sent SMS and emails are stored in the **Message Archive**.

= How do I send campaign messages via Telegram, Bale, Eitaa, Rubika, or WhatsApp? =
Go to **Settings** and, for Telegram/Bale/Eitaa/Rubika, create a bot on that platform and paste its token, then register the generated webhook URL with the bot. Once a customer starts a chat with your bot and shares their phone number, they become selectable in **Campaign → Messenger**. WhatsApp requires a Meta-verified WhatsApp Business (Cloud API) account; recipients must be added there manually since the store only ever has a phone number, not a WhatsApp opt-in.

== Changelog ==


= 4.5.1 =
- Fixed the Appanel SMS gateway integration: the previous implementation used a non-existent domain (`api.appanel.ir`), which caused `cURL error 6: Could not resolve host`. Replaced it with the correct **IPPanel Edge API** endpoint (`https://edge.ippanel.com/v1/api/send`) and the proper request format (Authorization header, E.164 phone numbers, `sending_type: webservice`).

= 4.5.0 =
- Added **Appanel** as a new SMS gateway option (requires an API Key and Sender Number, both configurable in Settings → SMS Gateway Settings). The API key is encrypted at rest using the same mechanism as the other gateways.

= 4.4.0 =
- Added a Webhook Health Check tool in Settings that tells apart two different causes of a webhook 404: the route never registering inside WordPress vs. something in front of WordPress (cache/WAF/hosting panel) blocking it from the outside.
- Added an optional "Custom API Base URL" field for Telegram, so a relay (e.g. a free Cloudflare Worker forwarding to api.telegram.org) can be used when the hosting server cannot reach Telegram directly — this is the standard workaround for Iran-based hosting, where Telegram is blocked at the network level, confirmed by the debug log ("cURL error 28 / Connection timed out").
- Clarified (with sources) in a new explanation box that no messenger platform — Telegram, Bale, Eitaa, Rubika, or WhatsApp — offers any way, official or unofficial, to look up a chat_id from a phone number alone; every one of them requires the customer to message the bot at least once first, by design, as a deliberate privacy protection. The two supported ways to link a customer (auto via bot + phone share, or manual entry) are the only ones any store's plugin could offer.
- Confirmed from the debug log that Bale sending is now working correctly end-to-end for chat_ids belonging to real customers (not the bot's own ID).

= 4.3.1 =
- Added a "Send Messenger Campaign" quick-action button to the Customers tab, matching the existing SMS/Email ones.
- Fixed a confusing (but harmless) display bug: the Bot Token / Access Token fields showed the raw encrypted value after saving, which looked like a wrong or corrupted token even though it was stored and used correctly. Fields now show a masked placeholder instead.
- Added a step-by-step guide (in Settings → Messenger Settings) on how to obtain a customer's chat_id, both via the automatic bot-link flow and manually via getUpdates.
- Added a specific diagnostic message when the server cannot reach api.telegram.org (cURL/connection errors) — common on Iran-based hosting, since Telegram is blocked there at the network level — shown both in Test Connection and in real send failures, with Bale/Eitaa/Rubika suggested as unaffected alternatives.
- Added a warning that a "Success" result only confirms the platform's API accepted the request, not that a person received it — sending to the bot's own numeric ID (instead of a real customer's chat_id) will report success but deliver nothing.

= 4.3.0 =
- Messenger Settings now shows one platform's fields at a time via a dropdown picker, instead of all five platforms at once (much shorter Settings page).
- Added a temporary Messenger Debug Log (toggle in Settings) that records the exact request/response for the last 30 send attempts, viewable directly on the Settings page — no server log access needed.
- Added a "Bot Username" field per platform to generate a one-tap join link (e.g. t.me/yourbot) — there is no API on any of these platforms to look up a chat_id from a phone number alone, so inviting the customer to message the bot themselves is the only way to link them. A "Copy invite link" button now appears next to any not-yet-linked customer in the Campaign → Messenger tab.
- Clarified in Settings that a "successful" send only confirms the platform's API accepted the request — it does not guarantee delivery to a specific chat_id (e.g. a stale or mistyped chat_id can still return success); use Test Connection and the debug log to verify further.

= 4.2.1 =
- Fixed a fatal error ("Cannot declare class PREMORMA_Order_Pro") caused by a class name collision between the main plugin class and the table-creation helper; the helper is now named `PREMORMA_DB_Tables`.
- Fixed messenger webhooks (Telegram/Bale/Eitaa/Rubika) returning 404: rewrite rules are now flushed on activation and once automatically for sites where the plugin was already active.
- Fixed the Message Archive table (and SMS log table) sometimes never being created on sites that were already active before this feature shipped, which silently dropped all campaign logging.
- Messenger campaign sends now show the specific error message per failed recipient instead of only a bare error count.
- Added a "Test Connection" button in Settings for each messenger platform, to verify a bot token / WhatsApp credentials actually work before running a real campaign.
- Added a per-platform Enabled/Disabled dropdown in Messenger Settings; disabled platforms are hidden from the Campaign → Messenger tab and rejected server-side even if requested directly.
- The Messenger campaign tab now uses a dropdown to choose which platform to send through, instead of separate tab buttons.

= 4.2.0 =
- Added a Messenger campaign tab (Telegram, Bale, Eitaa, Rubika, WhatsApp) alongside SMS and Email.
- Added per-platform settings for bot tokens / WhatsApp Cloud API credentials, encrypted at rest.
- Added secure server-side webhooks to link a customer's phone number to their chat_id after they message your bot; nothing is pushed to a customer who hasn't contacted the bot first.
- Removed a previous client-side script that exposed the Telegram bot token in the browser; all messenger credentials are now used server-side only.
- Fixed a file-loading bug where `database-tables.php` and the webhook handler were never actually being included due to a filename mismatch.

= 4.1.9 =
- Renamed to "Premium Order Manager for WooCommerce" to comply with WordPress trademark policy.
- No functional changes.

= 4.1.8 =
- Fully refactored to remove all inline CSS/JS – now properly enqueued.
- Added prefix `woomaster_` to all AJAX actions, options, and functions.
- Fixed `register_setting` sanitization (recursive).
- Replaced anonymous callback for `wp_mail_content_type` with named method.
- Lowered menu position and integrated under WooMaster parent menu.
- Added complete external services documentation.
- Fixed all PHPCS and Plugin Check warnings.

== Upgrade Notice ==

= 4.5.0 =
Added Appanel SMS gateway support.