# WEARFITS WooCommerce Integration

Add WEARFITS virtual try-on to WooCommerce / WordPress product pages.

## Architecture

1. A WordPress plugin or theme snippet enqueues
   `https://api.wearfits.com/widget/tryon.js`.
2. The product page injects localized product JSON via `wp_localize_script` or a
   data attribute.
3. A "Try on" button calls `Wearfits.openTryOn()`.
4. API calls are proxied through a WordPress REST or AJAX endpoint when the
   service API key must stay private.

## Enqueue + product JSON

```php
add_action( 'wp_enqueue_scripts', function () {
  if ( ! is_product() ) return;
  wp_enqueue_script(
    'wearfits-widget',
    'https://api.wearfits.com/widget/tryon.js',
    array(), null, true
  );
  global $product;
  wp_localize_script( 'wearfits-widget', 'WearfitsProduct', array(
    'id'       => $product->get_id(),
    'name'     => $product->get_name(),
    'category' => 'top',
    'images'   => wc_get_product_gallery_image_urls( $product ),
    'sizes'    => $product->get_attribute( 'size' ),
  ) );
} );
```

A "Try on" button then calls `Wearfits.openTryOn({ products: [WearfitsProduct] })`.

## Category mapping

Infer the WEARFITS category from WooCommerce categories and tags:

- top, shirt, blouse, tee -> `top`
- bottom, pants, skirt, shorts -> `bottom`
- dress, jumpsuit -> `full-body`
- shoes, sneakers, footwear -> `shoe`

When unsure, add a product-level admin setting.

## Security

- Never print service API keys into page HTML.
- Store keys in WordPress options with proper capability checks.
- Proxy job submission and polling through a server-side REST/AJAX endpoint for
  production stores.

## Deliverables checklist

- Enqueue snippet or plugin file.
- Product JSON injection.
- Button and modal launch code.
- REST/AJAX proxy endpoints (production).
- Manual test instructions.

The widget contract is in the `wearfits-virtual-tryon-widget` skill; the REST
API and proxy targets are in `wearfits-api-integration` and the OpenAPI spec at
https://api.wearfits.com/doc.
