=== Chat App Brasil ===
Contributors: lupeedesign
Tags: whatsapp, woocommerce, whatsapp notifications, abandoned cart, whatsapp button
Requires at least: 6.0
Tested up to: 6.9
Requires PHP: 7.4
Stable tag: 3.0.2
WC requires at least: 7.0
WC tested up to: 9.8
License: GPLv2 or later

Send automatic WhatsApp messages to WooCommerce customers. Order notifications, abandoned cart, PIX, tracking and WhatsApp button.

== Description ==

**Chat App Brasil** is the most complete WhatsApp plugin for WooCommerce. Connect your store to WhatsApp and send automatic messages to your customers at every step of their journey — from new order to post-sale follow-up.

Official integration with the **ChatAppBrasil** platform — no direct WhatsApp Business API setup required.

= Why Chat App Brasil? =

* ✅ **WhatsApp + WooCommerce native** — no complex setup
* ✅ **Floating WhatsApp button** with click tracking and full customization
* ✅ **Abandoned cart recovery** via WhatsApp (CartBounty Free & Pro)
* ✅ **PIX via WhatsApp** — automatic QR code (Mercado Pago & Asaas)
* ✅ **Order tracking** — Correios and Melhor Envio
* ✅ **WooCommerce Subscriptions** — renewal and cancellation notifications
* ✅ **Back In Stock** — notify customers when a product is available again
* ✅ **HPOS compatible** — WooCommerce 7.1+

= Main Features =

**Automatic Order Notifications**
Each WooCommerce status triggers a personalized message to the customer and
optionally to the administrator. Individual toggle per notification — message
is preserved even when deactivated. Supported statuses: new order, pending,
on-hold, processing, completed, cancelled, refunded, failed, order note,
custom statuses.

**Payments Tab — Mercado Pago PIX**
Automatic QR code and copy-and-paste code delivery. Two modes:
* Immediate: sends in real time
* Reminder: sends only if not paid after X minutes (cancels if paid before)
* PIX expired notification: alerts the customer when time expires

**Payments Tab — Asaas PIX**
Full integration with the Asaas gateway for PIX payments.
Same immediate/reminder options. QR code + copy-and-paste code.

**Payments Tab — Asaas Boleto**
Automatic delivery of the boleto link when an Asaas Boleto order is created.
Use %boleto_url% in the message to include the link.

**Payments Tab — PIX Expired**
Unified notification for Mercado Pago and Asaas when PIX expires without payment.
Configurable delay in minutes after PIX generation.

**Tracking Tab — Correios and Melhor Envio**
Automatic notification when an order is completed and a tracking code is available.
Detects Correios (WooCommerce Correios) and Melhor Envio automatically.
Tags: %tracking_code%, %tracking_url%

**Abandoned Cart Recovery**
Up to 3 follow-ups via CartBounty Free or Pro, configurable interval per step.
Independent toggle per follow-up.

**Aftersales**
Automatic message X hours after order completion.

**Back In Stock**
WhatsApp notification when a product returns to stock.

**Easy Digital Downloads (EDD)**
New order and completed order notifications for digital products.

**Contact Form 7 / Caldera Forms**
Messages triggered via contact forms with tag substitution, line breaks preserved.

**Floating WhatsApp Button**
Configurable SVG button: position, size (40-200px), edge offset (0-300px),
pulse effect, tooltip, pre-filled message, hide by device.

**Click Tracking**
Every button click is recorded via AJAX for visitors and logged-in users.

**Bulk Messaging**
Share posts/products with a contact list, personalized messages, customer import.

**Message Logs**
Statistics cards (sent, errors, dedup), expandable rows with order link,
resend button, separate tabs by type, pagination, direct order link.

**Private Order Notes**
Automatic note on every WhatsApp send with status, number, and resend link.

**Security**
Configurable deduplication, rate limiting, send hours filter, error monitoring
(auto-pause after 1h of failures), API errors in friendly language.

**HPOS Compatibility**
Fully compatible with WooCommerce HPOS (7.1+).

== Installation ==

1. Plugins > Add New > Upload Plugin > select the .zip
2. Activate the plugin
3. Chat App Brasil > Settings > enter your Access Token
4. Configure messages in Notifications, Payments, Tracking, and other tabs

== Available Tags ==

= Order =
%id%, %order_key%, %order_date%, %order_time%, %order_link%, %order_status%,
%product%, %product_name%, %order_subtotal%, %order_shipping%, %order_total%,
%order_discount%, %currency%, %cust_note%, %shipping_method%,
%payment_method_title%, %payment_url%

= Customer =
%billing_first_name%, %billing_last_name%, %billing_email%, %billing_phone%,
%billing_city%, %billing_state%, %billing_address_1%

= Shipping =
%shipping_first_name%, %shipping_address_1%, %shipping_city%, %shipping_state%

= Tracking =
%tracking_code% — tracking code (Correios or Melhor Envio)
%tracking_url%  — tracking link

= Payments =
%pix_code%    — PIX copy-and-paste code (Mercado Pago or Asaas)
%boleto_url%  — boleto link (Asaas)
%payment_url% — pending payment link

= Other =
%shop_name%, %note%
Spintax: {Hello|Hi|Hey} — random variation per send

== Frequently Asked Questions ==

= How do I send automatic WhatsApp messages in WooCommerce? =
Configure your token in Chat App Brasil > Settings and set your messages in Chat App Brasil > Notifications. WhatsApp messages are sent automatically on every order status change.

= Can I send the PIX QR code via WhatsApp? =
Yes. The plugin integrates with Mercado Pago PIX and Asaas PIX. The QR code is automatically sent as an image with the copy-and-paste code when the order is created.

= Does it work with WhatsApp Business? =
Yes. The ChatAppBrasil platform uses the WhatsApp Business API. You need an active account at chatappbrasil.com.

= How does abandoned cart recovery via WhatsApp work? =
Install CartBounty Free or Pro, configure your follow-ups in the Abandoned Cart tab, and the plugin automatically sends WhatsApp messages to customers who abandoned their cart.

= Can I send tracking codes via WhatsApp? =
Yes. Install WooCommerce Correios or Melhor Envio. When an order is completed with a tracking code, the plugin sends it automatically via the Tracking tab.

= The button does not appear =
Fill in the phone number in Chat App Brasil > Button.

= Messages not sending =
Confirm the Access Token, check the Logs, ensure the message is not empty.
Check for a "Sends paused" alert in the admin panel.

= Asaas PIX not sending =
Ensure the WooCommerce Asaas plugin is active and the order payment method
is "asaas-pix". The __ASAAS_ORDER meta must be saved.

= Tracking notification not sending =
The tracking code must be available when the order is marked as Completed.
Verify WooCommerce Correios or Melhor Envio is active with a code on the order.

= "Sends paused" alert showing =
WhatsApp disconnected. Go to dashboard.chatappbrasil.com, reconnect, and click
"Reactivate sends" in the admin alert.

== Changelog ==

= 3.0.2 =
* FIX: Abandoned cart reminder is no longer sent when the customer has already purchased. Before sending, the plugin checks via wc_get_orders (HPOS compatible) whether a paid order (processing or completed) already exists for the cart email or phone, and if so marks the cart as done to prevent resending
* UX: Abandoned carts screen now hides carts without a phone number and only shows carts created after plugin activation (wlp_install_date). Count and pagination adjusted to the same filters
* UX: Carts that converted into a sale now show a "(recovered)" badge in the Status WA column and a notice in the detail; the manual send button is hidden in those cases
* FILTER: New wlp_converted_order_statuses hook to customize which order statuses count as "already purchased" (default: processing and completed)

= 3.0.1 =
* ARCHITECTURE: wlp-main.php refactored from 3,300 to 1,942 lines using 7 PHP Traits
* ARCHITECTURE: Added includes/trait-wlp-api.php — HTTP client, send_msg, process_variables, QR image
* ARCHITECTURE: Added includes/trait-wlp-orders.php — process_states, order_receive, resend
* ARCHITECTURE: Added includes/trait-wlp-payments.php — MP PIX, Asaas PIX, Asaas Boleto, expired
* ARCHITECTURE: Added includes/trait-wlp-cart.php — CartBounty, abandoned_order, aftersales
* ARCHITECTURE: Added includes/trait-wlp-subscriptions.php — 7 WCS subscription events
* ARCHITECTURE: Added includes/trait-wlp-tracking.php — Correios and Melhor Envio
* ARCHITECTURE: Added includes/trait-wlp-bis.php — Back In Stock + watchers + cron
* PERFORMANCE: Admin panel CSS extracted to assets/css/wlp-admin.css (browser caching)
* PERFORMANCE: Public AJAX endpoint get_base_url removed; URL injected via wp_localize_script
* PERFORMANCE: Click retention cleanup (90 days) moved from public AJAX to daily cron
* SECURITY: Size limit (max 2 MB) and MIME allowlist (JPEG/PNG/WebP/GIF) enforced before media upload
* FIX: Button position normalization now correctly applies the legacy variant map
* CLEANUP: Dead variable $curl_err removed
* CLEANUP: wlp_autoresponders UI without backend removed from admin JS
* RELIABILITY: BIS watchers (save_post, meta, transition_post_status) registered as formal hooks
* UX: "📚 Tags" tab added to Notifications panel with full variable reference
* UX: Abandoned cart cron frequency configurable in Security settings (1/2/5/10 min)
* DEPRECATED: wlp_bis_legacy_hook(), remove_emoji(), wlp_wa_encoding() marked @deprecated

= 2.9.8 =
* PERFORMANCE: Abandoned cart cron frequency configurable (1, 2, 5 or 10 min), default 5 min
* RELIABILITY: BIS watchers registered as formal hooks (save_post, updated_post_meta, transition_post_status)
* DEPRECATED: wlp_bis_legacy_hook(), remove_emoji(), wlp_wa_encoding() marked @deprecated
* UX: Tags reference tab exposed in Notifications panel

= 2.9.7 =
* SECURITY: Public AJAX endpoint get_base_url removed; URL injected via wp_localize_script
* PERFORMANCE: Click retention DELETE moved from public AJAX to daily cron wlp_button_cleanup_clicks
* SECURITY: File size (max 2 MB) and MIME validation before media send
* CLEANUP: Dead variable $curl_err removed
* FIX: Button position normalization correctly applies $pos_map[$val]
* CLEANUP: wlp_autoresponders UI removed from JS (backend never implemented)

= 2.9.6 =
* SECURITY: MD5 replaced by wp_hash() for Access Token validation
* SECURITY: @unserialize replaced by is_serialized() + allowed_classes false
* SECURITY: Manual cURL replaced by WP_Http for media uploads
* PERFORMANCE: admin_init migration hook guarded (only registers when needed)
* CLEANUP: Lottie Player removed (hook + enqueue_lottie method)
* FIX: Button positions normalized (left-bottom → bottom-left)
* CLEANUP: uninstall.php now removes JSONL logs, migration flags and transients

= 2.9.0 =
* NEW: Asaas PIX integration — QR code + copy-and-paste code, immediate/reminder modes
* NEW: Asaas Boleto integration — boleto link via %boleto_url%
* NEW: PIX expired notification — shared between Mercado Pago and Asaas
* NEW: Payments tab — centralizes Mercado Pago PIX, Asaas PIX, Asaas Boleto, PIX Expired
* NEW: Tracking tab — Correios and Melhor Envio with automatic detection
* NEW: Tags %tracking_code%, %tracking_url% — tracking code and link
* NEW: Tags %order_status%, %order_time%, %payment_url% — new message tags
* FIXED: "Sends paused" notification appearing twice in admin panel
* UPDATED: readme.txt and readme-en_US.txt fully updated for v2.9.0

= 2.8.0 =
* NEW: PIX reminder, private order notes, per-notification toggle
* NEW: Expandable log rows, error monitoring, friendly API errors
* FIXED: Log statistics, CF7 line breaks, Clear Logs button

= 2.7.5 =
* Rate limiting, send hours filter, configurable dedup, Back In Stock, debug mode

= 2.7.0 =
* Full HPOS compatibility, wc_get_order(), WC_Order API

= 2.0.0 =
* SVG floating button with live preview, click tracking

= 1.0.0 =
* Initial release
