=== AI Product Attributes – Specs, Tags & SEO for WooCommerce ===
Contributors: dataalign
Tags: woocommerce, product attributes, product specs, product tags, seo
Requires at least: 5.6
Tested up to: 6.8
Requires PHP: 7.4
Stable tag: 0.1.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

AI enrichment for WooCommerce product attributes (specs), tags, and SEO — bulk or single, safe baseline + restore.

== Description ==

DataAlign.ai for WooCommerce connects your store to the DataAlign API to enrich product data. It’s designed to be safe by default, fast to use, and practical on real stores.

Key features:
- AI enrichment for product attributes (specifications), tags, and SEO meta.
- Specs first: Specs tab for product pages and `[dataalign_specs]` shortcode.
- One‑click Bulk Optimization with live progress bars and background processing.
- Targeted bulk from the Products list (only selected items) with automatic redirect to the Optimize tab.
- Baseline preservation + one‑click Restore (attributes, tags, and SEO) for safety.
- Tag best practice: applies at most 5 product tags per item.
- Optional mapping into popular SEO plugins (Yoast, Rank Math, SEOPress, AIOSEO, TSF).
- “Poll Now” button to apply finished jobs immediately when you’re watching.

Performance & reliability:
- Batches products efficiently and queues in the background (Action Scheduler when available, WP‑Cron fallback).
- Inline queuing of the first batch for instant feedback; shorter fallback delays between batches.
- Continues processing even if you close the browser or leave the page.

Privacy & safety:
- Sends only the product data you choose (title, description, categories, and optionally images) to the DataAlign API over HTTPS.
- You only need to set your API Key; the API base URL is fixed.
- No tracking. No ads. No telemetry.
- Stores enrichment results in post meta; baseline snapshots let you undo changes.
- Uninstall script cleans plugin options; post meta cleanup is left to site owners (documented).

== Installation ==

1. Upload the plugin to `wp-content/plugins` and activate it.
2. Go to WooCommerce → DataAlign AI and set your API Key.
3. Open a product and click “Enrich with DataAlign AI”, or select products in Products → Bulk actions → “Enrich with DataAlign AI (Bulk)”. You’ll be redirected to the Optimize tab to monitor progress.
4. Bulk optimization runs in the background even if you leave the page. Use “Poll Now” to apply completed jobs immediately.

= Configuration (Admin) =
- Settings location: WooCommerce → DataAlign AI.
- Tabs:
  - Connection: Add your API Key and test connection.
  - Attributes & Specs: Enable Specs Tab, set title, and control attribute syncing/overrides.
  - SEO: Optional mapping to SEO plugins; “Only Fill Empty” to avoid overwriting existing fields.
  - Optimize: Start/Cancel bulk, view progress, and Poll Now.
  - Restore: One‑click restore of baseline tags, attributes (and Woo snapshot), and SEO.
  - Advanced: Public Site Base URL for image rewriting during local development, and developer options.

== Usage ==

- Single product:
  - Edit any product and use the “Enrich with DataAlign AI” button in the side metabox. Attributes (specs), tags, and SEO are stored safely with a baseline so you can restore later.

- Bulk optimization:
  - From the Products list, select items and choose “Enrich with DataAlign AI (Bulk)”. You’ll be redirected to the Optimize tab, which shows two progress bars (queued and applied). Processing continues in the background even if you close the page.
  - Or start a full‑catalog run from the Optimize tab.

- Frontend (Product pages):
 - Specs Tab: Enable in Attributes & Specs. The plugin renders a clean specs table from DataAlign attributes on the single product page. Customize the tab title in settings.
 - Shortcode: Use `[dataalign_specs id="123"]` to render the same specs table anywhere (replace `123` with the product ID).
  - Additional Information Tab: Attribute labels are humanized for readability (e.g., `battery_capacity` → `Battery Capacity`). Optionally hide the WooCommerce “Additional information” tab when the Specs tab is enabled to avoid duplicate content.
  - SEO: If mapping to SEO plugins is enabled, enriched SEO is written into your active SEO plugin (respecting “Only Fill Empty” if selected).

== Frequently Asked Questions ==

= Are images required? =
No. Images can improve accuracy but are optional and can be excluded in settings.

= How do I get an API key? =
On the Connection tab click “Register Site (Get Free API Key)”. Your site is registered and the key is filled in automatically. Click “Save Settings”, then “Test Connection”. Until a key is present, other tabs stay disabled to prevent misconfiguration.

= What’s the minimum requirement to enrich? =
Each product must have a Title. A clear, detailed description helps improve accuracy.

= Will bulk optimization ever start automatically? =
No. Bulk optimization only starts when you click “Start Bulk Optimization” on the Optimize tab. Visiting the tab or reloading the page does not auto‑start a run.

= Does it keep working if I leave the page? =
Yes. Queueing and applying results run in the background using Action Scheduler (if available) or WP‑Cron fallback. You can return later to check progress on the Optimize tab.

= What does “Auto‑sync Attributes to Woo” do? =
When enabled, DataAlign attributes are copied into WooCommerce “Custom product attributes” (visible, non‑variation) after enrichment or when results are applied. For variable products, attributes used for variations (is_variation=1) are never modified — taxonomy or custom — so your variation logic remains intact. This makes specs immediately available to themes and the native “Additional information” tab.

= Will existing attributes/tags be overwritten? =
By default, no. The plugin preserves a baseline (pre‑AI) snapshot and keeps your existing attributes and tags unless you explicitly enable the “Override Existing …” options. You can restore to the baseline per product or in bulk at any time.

= How many tags are applied? =
To follow WooCommerce best practices, the plugin applies at most 5 tags per product. The API may suggest more, but no more than five are saved.

= Which SEO plugins are supported? =
Yoast, Rank Math, SEOPress, All in One SEO (AIOSEO), and The SEO Framework (TSF). Mapping is optional and respects an “Only Fill Empty SEO Fields” setting.

= How does SEO mapping choose a plugin when multiple are active? =
The plugin detects the SEO tool with existing post meta for the product; otherwise it follows a sensible precedence. You can also disable mapping entirely or set “Only Fill Empty” to avoid overwriting manual SEO.

= Is my data safe? =
Data is sent securely over HTTPS to the DataAlign API. The plugin does not include tracking, telemetry, or ads. Enrichment results are stored in post meta and a baseline snapshot lets you restore your original tags, attributes, and SEO.

= Can I run bulk only for selected products? =
Yes. From Products, select items and choose “Enrich with DataAlign AI (Bulk)”. You’ll be redirected to the Optimize tab with live progress — only your selected products are processed.

= The plan limit is reached — what happens? =
The plugin shows a friendly message with a link to upgrade your plan. Existing jobs may finish applying; new queueing is paused until you upgrade.

= Does this plugin store data? =
It stores enrichment results in post meta. You can delete plugin options on uninstall; post meta cleanup is optional via a filter. See `uninstall.php`.

= Will it change prices, stock, or variations? =
No. Enrichment only touches tags, attributes/specs, and SEO fields (plus Woo custom attributes when auto‑sync is enabled). It never changes stock, prices, orders, or variation structures — and it never modifies attributes used for variations.

= Local development: the API can’t reach my media, what do I do? =
Set “Public Site Base URL (optional)” in Advanced to a public tunnel (e.g., Cloudflare Tunnel/ngrok) so image URLs sent to the API are reachable. You can also enable “Exclude Images from Enrichment”.

= Cron requirements? =
Background polling uses WP‑Cron (or Action Scheduler if present). Ensure your site receives traffic, or configure a real cron to hit `wp-cron.php` periodically. The plugin registers a minute‑level schedule on activation.

= Who can use the admin actions? =
Users with the `manage_woocommerce` capability. Product‑level enrich/restore actions require `edit_product` for the specific product.

= Where can I see errors or usage? =
The settings page includes a Diagnostics box and a Usage panel. Usage loads only when a key is configured and is fetched lazily to keep the page fast.

== Screenshots ==
1. Settings screen with live connection test and tabs.
2. Product edit metabox with Enrich button and attributes table.
3. Optimize tab with progress bars and background processing message.
4. Specs tab output on the product page.

== Changelog ==

= 0.1.0 =
Initial release.
