# 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.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Connect WooCommerce with Vtryon for a seamless virtual try-on experience. Handles product mapping, image validation, and real-time status polling. This file is also rendered under **WooCommerce → Vtryon → Help guide** in wp-admin.

## 🚀 Key Features

- **Dynamic Authentication**: Automatically handles login and token caching using store credentials.
- **Automated Garment Syncing**: One-click sync to upload WooCommerce featured images and retrieve Garment IDs. **Sync All** on the Products list (or on a product category’s edit screen) runs sync only for products that still have no Garment ID, with live progress (completed / total). Hover the button for a short explanation.
- **Download control**: Under settings, you can show or hide the **Download result** button after a try-on completes; the result image and “Try another photo” remain available when download is hidden.
- **Image Validation**: Mandatory multi-step flow ensures user-uploaded photos meet AI quality standards before processing.
- **Granular Control**:
  - **Storewide master switch**: Enable or disable virtual try-on for the entire site (when off, the button is hidden everywhere regardless of product or category).
  - Optional **logged-in-only** visibility (guests do not see try-on).
  - Enable/Disable try-on per product category.
  - Enable/Disable try-on per individual product.
- **Product page placement**: Choose where the try-on block appears on the single product page (for example before or after add to cart, below the summary, or at the bottom of the page). Shortcodes remain available for custom layouts.
- **Polished UI**: Modern, non-blocking notifications powered by SweetAlert2 (Swal).
- **Efficient Polling**: Smart recursive polling prevents unnecessary server load and background process pile-up.
- **Developer Friendly**: Extensive hooks and filters for frontend customization and behavior modification.

## ✨ Coming Soon

The following features are planned for upcoming releases of this plugin:

- **Ready-to-use Catalog SKU Image Generation**
- **Pose Generation for the Same SKU**
- **Expanded AI fashion workflow support inside WooCommerce**

For now, if you want to generate **catalog-ready SKU images** or **additional poses**, please use the **Vtryon website or app**.

## 🛠 Installation

1. Install from the Plugins screen.
2. Activate the plugin through the **Plugins** menu in WordPress.
3. Ensure WooCommerce is installed and active.

## ⚙️ Configuration

1. Navigate to **WooCommerce → Vtryon**.
2. If you do not have an account yet, sign up at **https://vtryon.legresca.ai/app** using **Create Account**.
3. After signup, log in to your Vtryon account.
4. Enter the same **Email / Phone** and **Password** that you used while creating your Vtryon account.
5. Under **Storewide try-on**, leave **Enable virtual try-on for the entire site** checked unless you want to hide try-on everywhere (product and category toggles only apply when this is on).
6. Under **Product page placement**, pick where the try-on block should appear on single product pages (default: after add to cart). Exact order can vary slightly by theme.
7. (Optional) Under **Visibility**, check **Show the try-on button only for logged-in users** to limit try-on to logged-in customers.
8. Under **Download result button**, leave **Show the “Download result” button after a try-on completes** checked unless you want to hide the download control on the storefront (customers can still see the result image).
9. Click **Save Changes**. The plugin will automatically test the connection and show a status alert.

## 👕 How to Sync Products

1. Go to your **Products** list in WordPress.
2. Locate the **Garment ID** column.
3. Click the **Sync** button for any product. The plugin will upload the featured image and save the returned ID.
4. To sync many products at once that still have no ID, click **Sync All** in the toolbar above the product table. Progress shows as **completed / total**. Only products missing a Garment ID are included; products that already have an ID are skipped. If your catalog is very large, only the first batch runs per click (see filter `vtryon_bulk_sync_max_products`, default 2000)—run **Sync All** again until no products remain.
5. On **Products → Categories**, edit a category: under **Garment sync**, use **Sync All** to do the same for products in that category only (hover the button for the tooltip).
6. Alternatively, edit a product and use the **Sync with Vtryon** button in the **General** data tab.

## 🖥 Frontend Flow

Once a product has a **Garment ID**, try-on is **enabled** at the site and product/category level, and the customer passes any **logged-in-only** rule, the Try-On UI appears on the product detail page at the **placement** you chose in settings (or wherever you put the `[vtryon]` shortcode).

1. **User Upload**: Customer clicks **Upload Photo** and selects their portrait.
2. **Validation**: The plugin sends the photo for quality validation.
3. **Processing**: Once validated, the Try-On task is created automatically.
4. **Result**: After polling is complete, the final generated image is displayed to the user.
5. **Download**: If enabled in **WooCommerce → Vtryon → Settings** (**Download result button**), users can download the generated result directly.

## 🪝 Developer Hooks

### Filters
- `vtryon_upload_person_payload`: Modify data sent during person image upload.
- `vtryon_create_task_payload`: Customize the final task creation JSON.
- `vtryon_max_upload_size`: Change the maximum file size (default 5MB).
- `vtryon_default_garment_type`: Change the garment type (default `stitched`).
- `vtryon_display_preset_definitions`: Add or change **Product page placement** presets (each preset: `hook`, `priority`, `label`).
- `vtryon_display_position`: Override the resolved WooCommerce **hook**, **priority**, and **preset** slug used to output the try-on block on single product pages.
- `vtryon_bulk_sync_max_products`: Maximum number of products loaded per **Sync All** run (default `2000`).

### Actions
- `vtryon_before_upload_person`: Fires before a person image is sent.
- `vtryon_after_create_task`: Fires after a task is successfully initiated.
- `vtryon_before_download`: Fires before a user downloads the result.
- `vtryon_after_download`: Fires after a user downloads the result.

## 📋 Requirements

- WooCommerce 5.0+
- PHP 7.4+
- A valid Vtryon account

**Service provider**

Vtryon

**Privacy Policy:** https://vtryon.legresca.ai/privacy-policy

---

*Built for professional WooCommerce integrations.*
