=== E-Khata ===
Contributors: ekhata
Tags: erp, accounting, inventory, sync, ecommerce
Requires at least: 6.2
Tested up to: 7.0
Requires PHP: 7.4
Stable tag: 1.0.1
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Two-way sync between your WooCommerce store and E-Khata Cloud: products, prices and stock flow in; orders flow out to your books automatically.

== Description ==

E-Khata Cloud is an accounting and inventory platform for retail and wholesale businesses in Pakistan. This plugin connects your WordPress + WooCommerce store to your E-Khata business so the two stay in step without manual data entry.

**E-Khata is the master of your catalog.** Products, variants, prices and stock levels you manage in E-Khata are pushed into WooCommerce automatically — including images, categories and tags.

**WooCommerce is the master of orders.** When a customer places an order, the plugin notifies E-Khata so a sale is recorded in your books, stock is adjusted, and your daily khata stays accurate. Cancellations and refunds sync too.

**Blog publishing.** Marketing posts written in E-Khata can be published straight to your WordPress blog, with featured image and SEO fields (Yoast SEO and Rank Math supported).

= Features =

* One-time pairing with a short code — no API keys to copy around
* Product, variant, price and image sync (E-Khata → store)
* Absolute stock level sync so overselling stops
* Order, cancellation and refund notifications (store → E-Khata) with signed, verified webhooks and automatic retries
* Blog post publishing with SEO metadata
* Compatible with WooCommerce High-Performance Order Storage (HPOS) and block checkout
* A Sync health screen showing recent pushes, delivery queue state and logs

= Requirements =

* An E-Khata Cloud account (https://ekhata.ai)
* WooCommerce 8.0 or newer (required) — the plugin declares it as a dependency

== External services ==

This plugin connects your store to **E-Khata Cloud**, the service operated by E-Khata that you pair it with. It talks to the API base URL you enter on the settings screen (default: https://ekhata.ai/api). In addition, product and blog images are downloaded directly from the image URLs E-Khata returns, which may be served from E-Khata's storage/CDN hosts rather than the API base. No other third-party service is contacted.

Data **received** from E-Khata Cloud (inbound): your product catalog (titles, descriptions, prices, stock levels, images), and blog posts you author there.

Data **sent** to E-Khata Cloud (outbound):

* During pairing: your site URL, site name, a random site identifier generated by the plugin, plugin/WordPress/WooCommerce versions, and store currency.
* When orders are placed, cancelled or refunded: the order details — totals, taxes, discounts, line items, payment method, the customer note, and the customer's billing details (name, email, phone, address) — so the sale can be recorded in your books.
* On deactivation: a notification that the connection stopped.

Data is sent only after you explicitly pair the store, and stops when you disconnect. This data is processed under E-Khata's terms and privacy policy:

* Terms of service: https://ekhata.ai/terms
* Privacy policy: https://ekhata.ai/privacy

== Installation ==

1. Install and activate the plugin (WooCommerce should be active for full sync).
2. In E-Khata Cloud, open Settings → Integrations → WooCommerce and generate a pairing code.
3. In WordPress, go to WooCommerce → E-Khata, paste the code and press Connect.
4. Your catalog will begin syncing from E-Khata; new orders will appear in your E-Khata books automatically.

== Frequently Asked Questions ==

= Which side wins when data differs? =

E-Khata is the source of truth for products, prices and stock; the plugin overwrites those in WooCommerce. WooCommerce is the source of truth for orders; E-Khata never modifies your store orders.

= Does it work with High-Performance Order Storage (HPOS)? =

Yes. The plugin declares HPOS compatibility and uses only WooCommerce CRUD APIs for orders.

= Do abandoned or failed checkouts get sent to E-Khata? =

No. Only orders that reach processing, completed or on-hold are sent. Pending, failed and draft checkouts never leave your store.

= What happens if E-Khata Cloud is unreachable? =

Order notifications are queued locally and retried with increasing delays for up to a day. You can watch and retry deliveries under WooCommerce → E-Khata → Sync health.

= Can I disconnect? =

Yes — WooCommerce → E-Khata → Disconnect. The plugin deletes its credentials and stops all syncing. E-Khata Cloud is notified so the connection is closed on both ends.

= Does uninstalling remove my products? =

No. Uninstalling never touches your products, orders or posts. The plugin's own settings and delivery queue are removed; the small sync ID tags it stored on products/orders/posts are removed only if you ticked "remove data on uninstall".

== Screenshots ==

1. Connection tab — pairing the store with a code.
2. Sync health tab — inbound pushes and the outbound delivery queue.
3. Log tab — recent sync activity.

== Changelog ==

= 1.0.1 =
* Read the stored pairing credentials directly from the database so a persistent object cache (e.g. W3 Total Cache) can never report a genuinely-paired store as "not paired".

= 1.0.0 =
* Initial release: pairing, product/variant/image/stock sync from E-Khata, signed order webhooks with retry queue, blog post publishing, HPOS compatibility, sync health dashboard.

== Upgrade Notice ==

= 1.0.1 =
Fixes a "not paired" error on sites using a persistent object cache. Recommended for all users.

= 1.0.0 =
Initial release.
