=== bgremove for WooCommerce ===
Contributors: hyxor
Tags: woocommerce, background removal, product images, cutout, ai
Requires at least: 6.4
Tested up to: 6.7
Requires PHP: 8.1
Stable tag: 1.5.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Remove backgrounds from WooCommerce product images with the bgready API. Results land in the Media Library; originals are never deleted.

== Description ==

**bgremove for WooCommerce** lets shop owners paste a bgready API key and remove backgrounds from product images — one at a time, in bulk, or automatically when images change.

* WooCommerce → Settings → bgremove: API key, automatic processing, background / layout / output customisation (rendered by the API), live sample preview
* Signed job webhooks so results arrive without waiting for WP-Cron traffic; polling is only a fallback
* Apply new settings to the whole catalogue with a progress bar
* Product meta box with global or per-product overrides, before/after thumbnails, Process / Reprocess / Restore
* Bulk action on Products and Media Library
* New attachments named `<original>-nobg.png|jpg|webp`; product slots replaced only when you choose (or enable auto-replace)
* Respects API rate limits (429 Retry-After) and pauses on insufficient credits (402)

Requires a free or paid account at [bgready.com](https://bgready.com/).

== Installation ==

1. Upload the `bgremove-for-woocommerce` folder to `/wp-content/plugins/`, or install the zip via Plugins → Add New → Upload.
2. Activate the plugin (WooCommerce 8+ must already be active).
3. Open WooCommerce → Settings → bgremove, paste your API key, and click **Test connection** (registers the signed callback).
4. Optionally enable automatic processing and tune customisation defaults.
5. Open a product and use the **Background removal (bgremove)** meta box, or select products / media items and choose **Remove background (bgremove)**.

== Frequently Asked Questions ==

= Are original images deleted? =

No. Keep original is always on. Results are new Media Library attachments. Restore original switches the product slot back without deleting files.

= Does preview cost credits? =

Preview downloads are free (≤ ~500×500 px for square). Full-resolution output uses 1 credit per image.

= What happens when I run out of credits? =

The queue pauses and an admin notice links to the bgremove pricing page. Resume after topping up.

= Why did nothing change after I saved a new colour? =

Existing products keep their old results until you reprocess. After saving settings, use **Reprocess catalogue** (or Reprocess on a product).

== Changelog ==

= 1.5.0 =
* Change: default API base URL is https://api.bgready.com/api/v1 (legacy bgremove.hyxor.io still works).
* Add: settings notice with one-click “Switch to api.bgready.com” when the legacy base is configured.
* Change: pricing / docs links point at bgready.com.

= 1.4.1 =
* Add: “bgremove preset” dropdown — send a named RenderPreset from the editor </> API modal via preset=<id>.

= 1.4.0 =
* Add: Stock background picker (curated gallery via API).

= 1.3.0 =
* Add: Watermark settings (none / bgremove preset / custom text or image) with 3×3 position grid, opacity, size, margin, rotation, and tile.
* Add: Per-slot watermark scope (featured / gallery / variations) and product meta box Inherit / None / Preset / Custom.
* Add: Live sample preview draws a watermark overlay; API sends watermark / watermark_* params (image via multipart watermark_image_file).

= 1.2.1 =
* Fix: build callback URL with get_rest_url() so plain permalinks use ?rest_route= (wp-json paths do not work).
* Fix: always register/send the signed webhook on job create; add Test callback button (API ping + exact failure).
* Fix: catalogue progress counts completed results ("x / N done"), not queued items; finished only when all done/failed.
* Fix: when the last callback test failed, poll at 5 s / 10 s / 20 s instead of waiting 60 s.
* Fix: accept webhook.test pings; verify Bgremove-Signature with ±300 s tolerance matching the server.

= 1.2.0 =
* Add: signed job webhook callback (`/wp-json/bgremove/v1/callback`) so results save without waiting for WP-Cron.
* Add: polling only as a 60 s fallback; admin pages kick Action Scheduler via AJAX.
* Add: submit all product images at once (no one-at-a-time slot lock).
* Add: apply new settings to the catalogue with batched AJAX progress.
* Add: meta box status polling every 2 s with in-place before/after refresh.
* Change: remove obsolete Mode setting (server ignores modes).
* Change: colour picker + Media Library background chooser with thumbnails; live sample updates for colour, image, canvas, margin, shadow and output size.
* Fix: Preview sizing help aligned with server 500×500 square preview budget.

= 1.1.1 =
* Fix: do not enqueue a second job while an attachment is still queued or processing (15-minute stale window).
* Fix: default automatic processing is Featured image only on fresh installs (existing settings kept).
* Fix: result attachments use the product as post_parent when the original has none (Media Library "Uploaded to").
* Fix: replace native browser alerts with inline WordPress notices in the product meta box.
* Fix: clarify Preview (~500×500 px, free) vs Full (original resolution, 1 credit) in Resolution help text.

= 1.1.0 =
* Add: automatic processing (featured / gallery / variations) when product images change.
* Add: customisation defaults — background (transparent / white / colour / image), canvas, fit + margin, output size, shadow, format + quality, resolution.
* Add: live sample preview on the settings page.
* Add: per-product overrides meta box with before/after status, Process now, Reprocess, Restore original.
* Add: slot-aware auto-replace (featured, gallery position, variation); never re-process plugin results.
* Change: result downloads use API render options (no client-side image processing).

= 1.0.1 =
* Fix: saving settings or testing connection no longer overwrites a real API key with the masked display value.
* Fix: clearer Test connection errors for invalid key (401), credits (402), rate limit (429), and network failures.
* Add: Remove key checkbox to clear a stored API key (empty field keeps the current key).

= 1.0.0 =
* Initial release.
