=== Vtryon ===
Contributors: Vtryon
Tags: woocommerce, virtual try-on, fashion, ai, e-commerce
Requires at least: 5.8
Tested up to: 6.9
Requires PHP: 7.4
Stable tag: 1.0.2
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

AI try-on for WooCommerce: sync products with Vtryon, validate photos, show results—all handled server-side.

== Description ==

Vtryon connects your store to the Vtryon service so customers can upload a portrait photo and preview how a product looks on them.

**Key features**

* API token authentication: store your Vtryon API token server-side only (sent as x-api-key on each request).
* Smart garment syncing: **Sync** (product screen or Products list) opens a picker that lists the product’s gallery images so you can choose which image to send to Vtryon, or **upload from device** if the garment photo is not in the list. **Sync All** (Products list or category **Garment sync**) batch-syncs only products missing a Garment ID and always uses each product’s **main (featured) image**—you’ll see a confirmation explaining that before the run starts.
* Download control: optionally hide the **Download result** button on the storefront while keeping the result image and “Try another photo” (WooCommerce → Vtryon → Settings).
* Image validation: multi-step flow checks customer photos against AI quality rules before try-on runs.
* Granular control: storewide on/off for the whole site; optional logged-in-only mode; enable or disable try-on per product category and per product.
* Product page placement: choose where the try-on block appears on single product pages (WooCommerce hooks/priorities), with shortcode support for custom layouts.
* Polished admin and storefront UI with accessible notices (bundled SweetAlert2 on relevant screens).
* Efficient polling for validation and task status to limit unnecessary requests.
* Developer hooks and filters to adjust payloads, limits, and behavior.

**Coming soon**

Planned for future releases:

* Ready-to-use catalog SKU image generation
* Pose generation for the same SKU
* Expanded AI fashion workflows inside WooCommerce

For catalog-ready SKU images or extra poses today, use the Vtryon website or app: https://vtryon.legresca.ai/app

**Frontend flow**

When a product has a Garment ID and try-on is allowed (storewide setting, product/category toggles, and any logged-in-only rule), the try-on block appears on the product page at the placement chosen under WooCommerce → Vtryon → Settings, unless you output it only via the shortcode. The customer uploads a portrait (JPG/PNG), the image is validated, a try-on task runs, and the result is shown; downloading the file is available when **Download result button** is enabled in settings.

**Developer hooks**

*Filters*

* `vtryon_upload_person_payload` — person image upload payload.
* `vtryon_create_task_payload` — task creation JSON.
* `vtryon_max_upload_size` — max upload size (default 5 MB).
* `vtryon_default_garment_type` — garment type (default `stitched`).
* `vtryon_api_base_url` — override API base URL (advanced).
* `vtryon_display_preset_definitions` — register or change product page placement presets (`hook`, `priority`, `label` per preset).
* `vtryon_display_position` — override the resolved hook, priority, and preset slug for the single-product try-on block.
* `vtryon_bulk_sync_max_products` — max products per **Sync All** run (default 2000).

*Actions*

* `vtryon_before_upload_person` — before sending a person image.
* `vtryon_after_create_task` — after a task is created.
* `vtryon_before_download` / `vtryon_after_download` — around result download tracking.

**Requirements**

* WooCommerce (active)
* PHP 7.4+
* A valid Vtryon account (sign up at https://vtryon.legresca.ai/app )

== Installation ==

1. Install from the Plugins screen.
2. Activate the plugin.
3. Install and activate **WooCommerce**.
4. Go to **WooCommerce → Vtryon**. If you do not have an account, sign up at https://vtryon.legresca.ai/app (Create Account).
5. Generate an **API token** in your Vtryon dashboard (see https://vtryon.legresca.ai/guide/api-integration), paste it under **API token**, and save. The plugin tests the connection and shows a status notice.
6. Under **Storewide try-on**, keep **Enable virtual try-on for the entire site** checked unless you want try-on hidden everywhere (category/product settings apply only when this is on).
7. Under **Product page placement**, choose where the try-on block appears on single product pages (default: after add to cart).
8. (Optional) Enable **Visibility** to show the try-on button only to logged-in users.
9. Under **Download result button**, choose whether to show the download control after a try-on completes.
10. For each product: add product images (gallery), enable Vtryon on the product, and click **Sync with Vtryon** (product edit screen) or **Sync** in the **Garment ID** column. A dialog lists gallery images to choose from, or you can upload a different file from your computer. **Sync All** on the Products list (or **Garment sync** on a category) asks for confirmation first: it syncs every product still missing a Garment ID using **only the main (featured) image** for each product; products that already have a Garment ID are skipped.

== Frequently Asked Questions ==

= Does this require WooCommerce? =

Yes. The plugin checks for WooCommerce and shows an admin notice if it is missing.

= Are API credentials exposed to visitors? =

No. Only the WordPress REST URL and a REST nonce are passed to the browser; the API token and garment APIs run on the server.

= What image formats are supported? =

Featured images and customer uploads use **JPG** and **PNG** (validated with WordPress file checks).

= Does the plugin load third-party scripts on my store? =

The plugin bundles SweetAlert2 for admin sync feedback and storefront messages. No remote script loads are required for core operation.

= Can I turn off try-on for the whole store or move the try-on block? =

Yes. Use **WooCommerce → Vtryon → Settings**: uncheck **Enable virtual try-on for the entire site** to disable try-on site-wide, and use **Product page placement** to change where the block appears. For a custom position you can also use the `[vtryon]` shortcode (and remove the automatic hook in code if you need only the shortcode).

= How do I choose which image is synced to Vtryon for a product? =

Use **Sync with Vtryon** on the product edit screen or **Sync** in the **Garment ID** column on the Products list. A dialog lists the product’s gallery images; pick one or choose **upload from device** for a file that is not in the gallery. **Sync All** does not show this dialog—it syncs each qualifying product using its **main (featured) image** only, after you confirm.

= Where is the full Markdown documentation? =

The same documentation ships as `README.md` in the plugin folder. It is also shown under **WooCommerce → Vtryon → Help guide** below the quick start section.

== External services ==

This plugin connects to the **Vtryon** service (operated by Legresca) to provide AI virtual try-on functionality.

**What the service is used for**

* Merchant authentication — the store owner's Vtryon API token is sent with each API request (x-api-key header).
* Garment sync — product featured images are uploaded to Vtryon so the AI can dress customers in them.
* Person image upload — when a customer initiates a try-on, their uploaded portrait is sent to Vtryon for processing.
* Person image validation — Vtryon checks the uploaded photo against quality rules (lighting, face detection, pose) before running the try-on.
* Try-on task creation — Vtryon combines the person image and the garment to generate the try-on result.
* Status polling — the plugin queries Vtryon to check when the result is ready.
* Result retrieval — the generated try-on image URL is retrieved from Vtryon and stored privately on the WordPress side; the image is then served to the customer through a WordPress-side proxy, so the raw Vtryon URL is never exposed to the browser.

**What data is sent and when**

* **API token** is sent to the Vtryon API with each server-side request (x-api-key header). The token is stored only in the WordPress database and is never sent to the browser.
* **Product images** are sent when the merchant syncs a product with Vtryon (the image chosen in the sync dialog or uploaded from the merchant’s device) or when **Sync All** runs (each product’s main / featured image only).
* **Customer portrait photos** are sent to Vtryon only when a site visitor explicitly initiates a virtual try-on and agrees to the consent notice on the product page. Photos are not stored locally by the plugin.
* **Session / task identifiers** are exchanged between WordPress and the Vtryon API during status polling and result retrieval. These identifiers are kept server-side only and are never passed to the visitor's browser.

**Service provider**

Vtryon

**Privacy Policy:** https://vtryon.legresca.ai/privacy-policy

**Terms of Service:** https://vtryon.legresca.ai/terms

== Changelog ==

= 1.0.2 =
 * API token authentication (x-api-key) replaces email/password login.
 * Garment sync: choose a product gallery image or upload from your device (product edit/add screen and Products list **Sync**). **Sync All** confirms that batch sync uses each product’s main (featured) image only.

= 1.0.1 =
 * Improved Photo Guidelines & Consent model UX.

= 1.0.0 =

* Initial release on WordPress.org guidelines baseline.

== Upgrade Notice ==

= 1.0.2 =

Uses API tokens (not email/password), and adds the garment image picker plus **Sync All** confirmation. Enter your API token under WooCommerce → Vtryon after updating.

= 1.0.0 =

Initial release.
