=== VisWapp Chat Widget ===
Contributors: vectorilo
Tags: chat, live chat, whatsapp, whatsapp login, abandoned cart
Requires at least: 5.8
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 1.3.1
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

VisWapp chat widget, one-tap "Continue with WhatsApp" login and WhatsApp reminders for abandoned WooCommerce carts.

== Description ==

Paste the install snippet from your VisWapp account and the chat bubble appears on your site. No code to edit.

* Paste the snippet once; the plugin reads your widget ID and settings from it.
* Show the widget on every page, every page except some, or only some pages.
* Hide it from roles such as Administrator or Shop manager.
* Optional: identify logged-in customers so chats arrive with their name, email and phone (WooCommerce billing phone supported). Identities are signed on your server with your Identity secret, which never reaches the browser.
* When an identified customer logs out, their chat is cleared from that browser.
* Login with WhatsApp: a "Continue with WhatsApp" button on the WordPress login page, WooCommerce My account and checkout, or anywhere with the [viswapp_login] shortcode. WhatsApp opens with a message ready; the customer taps send and is logged in. Existing users are matched by WhatsApp number or WooCommerce billing phone; new numbers can get an account automatically.
* Abandoned cart recovery (WooCommerce): carts are sent to VisWapp once the shopper's phone or email is known, and VisWapp sends a WhatsApp reminder with a link that restores the cart and opens checkout.

== Installation ==

1. In WordPress, go to Plugins → Add New → Upload Plugin, choose viswapp-chat-widget.zip, then Install Now and Activate.
2. In VisWapp, open Chat Widget, save your widget, and copy the Install snippet.
3. In WordPress, go to Settings → VisWapp, open the Chat widget tab, paste the snippet, and Save Changes.
4. In VisWapp, add your site's domain under Chat Widget → Domains & identity → Allowed websites.
5. Open your site in a private window: the chat bubble appears in the corner.

To identify logged-in customers:

1. In VisWapp, copy the Identity secret from Chat Widget → Domains & identity.
2. In WordPress, on the plugin's settings page, turn on "Identify logged-in users", paste the secret, and save.

To add Login with WhatsApp:

1. In VisWapp, open Integrations → WhatsApp Login. Under Setup add your site's domain to Allowed domains, and add the Redirect URL shown on the plugin's settings page.
2. Under Developers, copy the Client ID and the Client secret (Reveal).
3. In WordPress, go to Settings → VisWapp, open the Login with WhatsApp tab, turn it on, paste both, choose where the button shows, and save.
4. In VisWapp, click Go live when you are ready (test mode works on your allowed domains too).

To turn on abandoned cart recovery (WooCommerce):

1. In VisWapp, open Integrations → WooCommerce → Abandoned carts and copy the Delivery URL and the Webhook secret.
2. In WordPress, go to Settings → VisWapp, open the WooCommerce tab, turn on "Capture abandoned carts", paste both, and save.
3. Click "Send test event". "HTTP 200" means VisWapp received a signed test cart.

== Abandoned cart recovery ==

The WooCommerce tab appears when WooCommerce is active.

What is sent: whenever the cart changes (add, remove, quantity, coupon, emptied) or the shopper's contact details become known, the plugin sends one signed `cart.updated` to your VisWapp Delivery URL at the end of that page request (in the background, so pages don't wait). Nothing is sent until a phone number or email is known, and an unchanged cart is not sent again on refresh. When the order is placed, `cart.converted` is sent with the order number. Requests are signed like WooCommerce webhooks (X-WC-Webhook-Signature, HMAC-SHA256 with the Webhook secret).

Where the phone comes from: logged-in customers use their WooCommerce billing phone and email. Guests are captured on the checkout page as they type: the classic checkout (billing phone, email, first and last name) and the block checkout (email and the billing or shipping phone and name) both post the fields to this site, which keeps them in the WooCommerce session. Numbers without a country code get the billing country's (or the store's) calling code.

Consent: optionally show a "Send me cart and order updates on WhatsApp" checkbox at checkout (your wording). With it on, VisWapp only reminds shoppers who ticked it (or opted in through Login with WhatsApp). The block checkout shows it with WooCommerce 8.9 or later.

The cart link: each reminder contains a link such as https://yourstore.com/?viswapp_recover=…. It rebuilds the cart (replacing what is in the browser's cart), fills in the shopper's details, applies the optional Recovery coupon and opens checkout. Links work for 14 days and stop working once the order is placed; an expired link opens the cart with a notice.

Cart identity: each cart is reported under the WooCommerce session's customer id for guests, or u<user ID> for logged-in customers. A cart keeps the key it was first reported under, also when the guest logs in, so it stays one cart in VisWapp; after an order the next cart starts fresh.

Developers can change or skip a body with the viswapp_woo_cart_payload filter:

    add_filter( 'viswapp_woo_cart_payload', function ( $payload, $topic ) {
        return $payload; // return null to skip sending
    }, 10, 2 );

== External services ==

This plugin connects your site to VisWapp (https://viswapp.com), a WhatsApp Business messaging service. Nothing is loaded or sent until you enter your VisWapp details on Settings → VisWapp, and each feature below works only when you turn it on.

* Chat widget. On the pages you choose, visitors' browsers load the widget script from the address in your install snippet (by default https://cdn.viswapp.com/w.js) and talk to your VisWapp Data API address. The widget sends the page address and referrer, the page and browser language, basic device details (browser, screen size, time zone), UTM parameters and what the visitor types in the chat. With "Identify logged-in users" on, the logged-in user's ID, name, email and phone number are sent, signed on your server.
* Login with WhatsApp. On the login, My account and checkout pages (and wherever you place [viswapp_login]) browsers load login.js from your VisWapp sign-in address. When a customer signs in, your server sends the one-time code and your client credentials to that address (/oauth/token) and receives the customer's verified WhatsApp number.
* Abandoned cart recovery (WooCommerce). Once a shopper's phone number or email is known, your server sends the cart (products, quantities, prices, totals, cart link) and the shopper's name, phone number, email, country and marketing consent to your VisWapp delivery URL, and again when the cart changes or the order is placed.

VisWapp terms of service: https://viswapp.com/terms-conditions
VisWapp privacy policy: https://viswapp.com/privacy-policy

== Privacy ==

With abandoned cart recovery on, cart contents (products, quantities, prices, totals) and the shopper's name, phone number and email address are sent to VisWapp so WhatsApp cart reminders can be sent. The plugin adds suggested text to Settings → Privacy → Policy guide; add it to your privacy policy. Use the consent checkbox where the law requires opt-in for marketing messages. Cart links are stored on your site for 14 days.

== Frequently Asked Questions ==

= Can I put the WhatsApp login button on my own page? =

Yes, with the shortcode:

    [viswapp_login label="Sign up with WhatsApp" redirect="/my-account/"]

Or link any button to /wp-json/viswapp/v1/login/start to use the hosted VisWapp login page.

= How are WhatsApp logins matched to users? =

By the viswapp_phone user meta (set on first login), then the WooCommerce billing phone. Developers can change this with the viswapp_login_find_user filter, and react to logins with the viswapp_login_success action:

    add_action( 'viswapp_login_success', function ( $user, $claims ) {
        // $claims: phone_number, name, whatsapp_opt_in, new_user, ...
    }, 10, 2 );


= The chat bubble doesn't appear =

Check that the settings page says "The widget is live on your site", that your domain is in Allowed websites in VisWapp, and that you are not logged in with a role you chose to hide it from. Clear your caching plugin's cache after saving.

= Does it work with caching plugins? =

Yes. The widget loads in the browser, so cached pages show it. If you identify logged-in users, make sure pages for logged-in visitors are not cached (most caching plugins already skip them).

= Can a developer change what is sent for a customer? =

Yes, with the viswapp_widget_identity filter. Return null to skip identifying a user:

    add_filter( 'viswapp_widget_identity', function ( $identity, $user ) {
        $identity['phone'] = get_user_meta( $user->ID, 'mobile', true );
        return $identity;
    }, 10, 2 );

Use the viswapp_widget_show filter to show or hide the widget on a request:

    add_filter( 'viswapp_widget_show', function ( $show ) {
        return $show && ! is_page( 'careers' );
    } );

= Can I open the chat from my own button? =

Yes. Add this to the button's link or a script on the page:

    <a href="#" onclick="window.VisWapp && VisWapp.open(); return false;">Chat with us</a>

= Does abandoned cart capture work with caching plugins? =

Yes, as long as the cart and checkout pages are not cached (WooCommerce tells caching plugins not to cache them). Carts are sent from the server during the request that changed them, so a cached product page doesn't stop capture.

= What happens when I delete the plugin? =

Its settings, the saved Identity secret, the WhatsApp Login and abandoned-cart secrets, and saved cart links are removed from WordPress. Chats, contacts and carts stay in VisWapp.

== Screenshots ==

1. Paste your install snippet in Settings → VisWapp and the widget goes live.
2. The VisWapp chat widget on your store.
3. One-tap "Continue with WhatsApp" login on checkout.
4. Login with WhatsApp settings.
5. Abandoned cart recovery settings for WooCommerce and The WhatsApp reminder with a link that restores the cart.


== Changelog ==

= 1.3.1 =
* The chat widget tells VisWapp the page language (data-lang, follows WPML / Polylang / TranslatePress), so multi-language chat flows can open in it. Filter: viswapp_widget_language.

= 1.3.0 =
* Abandoned cart recovery for WooCommerce: signed cart.updated / cart.converted events to VisWapp, guest phone and email capture on the classic and block checkout, optional WhatsApp consent checkbox, cart links that rebuild the cart and open checkout (with an optional coupon), and a Send test event button.
* Privacy policy suggestion for the data sent to VisWapp.

= 1.2.0 =
* Login with WhatsApp inside WhatsApp's own browser: the Continue button in WhatsApp's reply signs the customer in and brings them back to the page they were on.
* login.js is loaded with the plugin version, so updates reach browsers straight away.

= 1.1.0 =
* Login with WhatsApp: wp-login, WooCommerce My account and checkout, [viswapp_login] shortcode, hosted login page and chat-flow sign-in links.

= 1.0.0 =
* First release.
