=== MagizAI: AI Chatbot & Live Chat for WooCommerce ===
Contributors: magizai
Tags: ai, chatbot, live chat, woocommerce, customer support
Requires at least: 5.8
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 1.3.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

An AI assistant that answers from your own pages and products, hands chats to your team, and can check a signed-in customer's orders.

== Description ==

MagizAI is an AI chat assistant for your site. It answers visitors from your own content and passes the conversation to a person on your team when it should. MagizAI is a paid hosted service (plans at https://magiz.ai/pricing), and this plugin connects your account to WordPress and WooCommerce.

**The chat, knowing who is asking.** Enter your widget key and the chat appears on your pages. Add your identity secret and the plugin signs a short-lived token for a signed-in user on your own server, so the assistant can answer "where is my order?" for that person only. The secret never reaches the browser.

**Training that keeps up.** Switch sync on and your pages, posts and product descriptions go to MagizAI once a day, and about a minute after you publish, edit or trash something. Sending a page again replaces the old copy, and pages you delete here are removed there. Prices and stock stay out on purpose and come live from the tools below.

**Live answers through MCP.** The plugin runs a Model Context Protocol server at `/wp-json/magizai/v1/mcp`. Switch it on, connect it in MagizAI, and the assistant can use these tools during a chat:

* Site (5 tools): site details, search pages and posts, read a page, recent posts, topics.
* Property listings (2 tools, only with the Houzez, RealHomes or WP Residence theme): search published listings by place, sale or rent, type, price and bedrooms, and read one in full.
* Events (2 tools, only with The Events Calendar): upcoming events by words, category and days ahead, and one event in full with venue, organizer, cost and, with Event Tickets, each ticket's price and stock.
* Shop (15 tools, needs WooCommerce): product search and details, stock, sizes and colours, categories, featured and related products, reviews, delivery costs, payment methods, policy pages, discount codes, add-to-basket and discount links, back-in-stock requests.
* Customer (7 tools, off by default): a signed-in customer's orders, order status, tracking, downloads, a reorder link, an account summary and account links.
* Changes (5 tools, off by default): cancel an order that is not paid or shipped, record a refund request, change a delivery address before dispatch, add a note to an order, send a password reset email.

**Confirmation codes from your own site.** Before a change on a customer's account, MagizAI can ask your site to email the customer a 6-digit code. It goes to the address on the account they are signed in to, never to one typed in the chat, in your WooCommerce email template or a plain WordPress email. At most 5 codes an hour per customer; switch it off under Settings → MagizAI.

**Booking forms.** Add `[magizai_booking form="your-key"]` or the "MagizAI booking form" block to any page. Show the form inline, or as a button with `mode="button" label="Book now"`. Times, prices and the booking itself are handled by your MagizAI workspace.

= What the plugin will not do =

* Quote a price, stock level or policy from an old copy. The tools read WooCommerce at the moment of asking.
* Tell one customer about another's order. Every lookup checks the order belongs to the email asked about, and a refusal reads exactly like "no such order".
* Move money. A refund request is recorded and emailed to you.
* Show a full street address. House numbers come back masked.

= Before you switch on the customer tools =

MCP gives a tool no way to check who is on the other end. MagizAI checks the visitor's signed identity and fills the `email` argument from it, but only if you bind it. In MagizAI, open Skills → MCP → your server and bind every `email` argument to the verified identity claim `email`. Mark the change tools Sensitive so the customer confirms first. That is why these tools ship switched off.

== Installation ==

1. Install the plugin from Plugins → Add New, or upload the zip, then activate it.
2. Go to Settings → MagizAI.
3. Paste your widget key (MagizAI → Chatbots → Install) and your identity secret.
4. To keep the assistant trained, add your chatbot key and a REST API token, and tick the sync box.
5. For live answers, tick "Switch it on" under MCP, generate a token, and connect `https://your-site/wp-json/magizai/v1/mcp` in MagizAI as a Streamable HTTP server with Bearer auth.

== External services ==

This plugin connects your site to MagizAI (https://magiz.ai), the hosted AI chat service it is built for. It needs a MagizAI account and sends nothing until you enter your own keys.

**Chat widget.** Shows the chat. Once you enter a widget key, each visitor's browser loads `https://magiz.ai/widget.js` on the pages you chose. MagizAI receives what the visitor types, any file they attach, the page address, and a random visitor ID kept for a year in a first-party cookie and local storage, so a conversation follows them between pages. While the page is open the widget also tells MagizAI which page the visitor is on (address, title, referrer, time zone) so your team can see who is online; you can switch this off in MagizAI. Behaviour tracking (pages and products viewed, cart, scroll depth) stays off unless you switch it on in MagizAI. Both are skipped when the browser sends Do Not Track.

**Signed-in users.** If you enter an identity secret, a signed-in user's pages carry a token with their user ID, email address, name, billing company and language. MagizAI reads it to know who is asking. Guests get no token.

**Booking forms.** Pages with a booking shortcode or block load `https://magiz.ai/booking.js`. MagizAI receives the visitor's choices and the details they type into the form.

**Content sync (off by default).** When on, your server sends the title, address and text of the published posts and pages you pick, plus product names, SKUs, categories, descriptions and attributes, to `https://magiz.ai/api/v1/chatbots/{chatbot key}/knowledge`. It runs daily, a minute after you publish, edit or trash something, and when you press "Sync content now". It also fetches the list of documents it sent before so it can delete those that no longer exist. No customer data is sent.

**MCP and confirmation codes (off until you generate a token).** These are calls from MagizAI to your site at `/wp-json/magizai/v1/mcp`, `/wp-json/magizai/v1/verification_send` and `/wp-json/magizai/v1/capabilities`, accepted only with your token. Your site answers with what the tool found: products, stock, delivery costs, published property listings and events, and, with the customer tools on, the signed-in customer's orders. For a code, MagizAI sends the code and the customer's identity token, and your site replies with the masked address it wrote to. The code is not stored or logged here.

MagizAI terms of service: https://magiz.ai/terms
MagizAI privacy policy: https://magiz.ai/privacy

== Frequently asked questions ==

= Does it work without WooCommerce? =

Yes. The chat, sync, booking forms and site tools work on any WordPress site. The shop and customer tools appear only when WooCommerce is active.

= Will it slow my pages down? =

The chat script loads in the footer with `defer`, so the browser runs it after reading the page. The MCP tools run only when MagizAI calls them, never on a page view.

= Where does my data go? =

Text you choose to sync is stored in your MagizAI workspace. Order lookups are answered live from your database and the plugin keeps no copy. The activity log under Settings → MagizAI holds the tool name and the email asked about, on your own site, capped at 200 entries. Deleting the plugin removes its settings, log, back-in-stock list, code timestamps and scheduled sync.

= Which real-estate themes and event plugins work? =

Houzez, RealHomes and WP Residence (detected by the active parent theme and its listing post type), and The Events Calendar with or without Event Tickets. On any other site those tools stay hidden. They read only what a public listing or event page shows: never a private note, agent contact details, a listing's street address, attendees or orders.

= Can I add my own tools? =

Yes, with the `magizai_mcp_tools` filter: a name, a description, an input schema of named scalar properties, and a handler that returns text.

= Where can I get help? =

Contact the MagizAI team at https://magiz.ai/contact.

== Screenshots ==

1. Settings → MagizAI: the chat, signed identity and content sync.
2. The MCP section: endpoint, token and the tool groups switched on.
3. The chat on a WooCommerce product page.
4. The booking form block in the editor.

== Changelog ==

= 1.3.0 =
* New: property_search and property_details for sites on the Houzez, RealHomes or WP Residence theme. Published listings only; prices, rooms, size, location, features and a short description.
* New: events_upcoming and event_details for The Events Calendar, in the site's timezone, with ticket prices and stock from Event Tickets. Read only.
* Both sit with the site tools and appear only when their theme or plugin is active.

Earlier versions are listed in changelog.txt.

== Upgrade notice ==

= 1.3.0 =
Adds read-only property tools for Houzez, RealHomes and WP Residence, and event tools for The Events Calendar. Re-sync the MCP server in MagizAI to pick them up.

= 1.2.1 =
Fixes signed-in customer identity and the booking button. After updating, open Settings → MagizAI and press Save once so the plugin uses https://magiz.ai.
