=== Enable Block Editor for WC Products ===
Contributors: j.conti
Tags: woocommerce, gutenberg, block editor, products, variations
Requires at least: 6.4
Tested up to: 7.0
Requires PHP: 7.4
Stable tag: 1.0.0
License: GPL-3.0-or-later
License URI: https://www.gnu.org/licenses/gpl-3.0.html

Enables the block editor (Gutenberg) for WooCommerce products and keeps variation edits when pressing "Update", via an extensible saver framework.

== Description ==

Enable Block Editor for WC Products turns on the WordPress block editor (Gutenberg) for WooCommerce products and provides a generic, extensible **saver framework** so plugin data persists when you press "Update". The bundled reference adapter fixes WooCommerce variations: variation edits persist on "Update" without having to click the variations panel "Save changes" button.

**Why this plugin exists.** WooCommerce is not going to add block-editor support to the current product editor. Instead, it will eventually release a brand-new product editor (v3) — a completely fresh interface — but that work is only just starting and may take a long time to ship. Until that day comes, this plugin lets you edit your WooCommerce products with the block editor (Gutenberg) **today**. It is a temporary bridge, not a permanent replacement: when the new v3 product editor is finally released, you can simply deactivate this plugin.

This also addresses the silent data loss described in WooCommerce issue [#35242](https://github.com/woocommerce/woocommerce/issues/35242), which will not be fixed in the current editor: WooCommerce does not support the core block editor for products, so panels that save over their own AJAX channel can lose data on "Update". This plugin bridges that gap in the meantime.

= What actually breaks in Gutenberg (and what does not) =

When the block editor is enabled for products, pressing "Update" saves the post over REST. Two kinds of third-party data behave differently:

1. **Standard meta boxes** that save on `save_post` reading `$_POST` already persist in Gutenberg via WordPress' meta box compatibility layer. They need nothing from this plugin.
2. **Save routines bound to the classic form submit via a private AJAX channel** (WooCommerce variations, or a panel with its own AJAX save/actions) break, because that submit event does not exist in the block editor. The generic solution is a **savers registry** that each plugin opts into.

This plugin is that framework. The WooCommerce variations saver is just the bundled reference adapter, registered through the same public API any third party uses.

= How it works =

The bridge listens to the Gutenberg save cycle (`wp.data.subscribe`, the saving→saved transition, autosaves ignored). On each save it runs the registered savers; each saver re-triggers a native save (typically by clicking the plugin's own button) only when its rows are dirty. The bundled adapter clicks WooCommerce's `button.save-variation-changes` when there are `.variation-needs-update` rows, firing WooCommerce's own `woocommerce_save_variations` AJAX (which carries its nonce and capability checks). The plugin never serializes fields by hand and adds no REST endpoints.

= Two strategies =

* **Bridge (default):** Gutenberg on all products plus the variation save bridge.
* **Classic (fallback):** variable products edit in the classic editor; the bridge is not loaded. Enable with `define( 'EBEFWCP_MODE', 'classic' );` or the `ebefwcp_mode` filter.

= For plugin developers =

Register your own saver through the public API exposed on `window.ebefwcp`:

`window.ebefwcp.registerSaver( { id: 'my-plugin/my-panel', dirtySelector: '#my_panel .my-row.needs-update', buttonSelector: 'button.my-plugin-save' } );`

Full JS and PHP extension points, plus an AJAX integration guide, are documented in the plugin's `docs/api/` directory.

== Installation ==

1. Upload the plugin to `wp-content/plugins/enable-block-editor-for-wc-products/`, or install it through the Plugins screen in WordPress.
2. Ensure WooCommerce is installed and active (required). If it is not, an admin notice appears and the plugin stays inactive in effect.
3. Activate "Enable Block Editor for WC Products" through the Plugins screen.

Product edit screens then load in the block editor, and pressing "Update" persists variation edits — no need to click the variations panel "Save changes" button.

== Frequently Asked Questions ==

= Does it require WooCommerce? =

Yes. WooCommerce 7.0 or newer is required (`Requires Plugins: woocommerce`). If WooCommerce is not active, the plugin shows an admin notice and does nothing.

= Will my third-party meta boxes still save? =

Standard meta boxes that save on `save_post` from `$_POST` already persist in Gutenberg and need nothing extra. Panels that save through their own AJAX channel must opt in by registering a saver via `window.ebefwcp.registerSaver()`.

= I need to edit a product with a plugin that uses AJAX and is not adapted. Can I switch to the classic editor just for that product? =

Yes. On the product edit screen there is an **Editor** box with an **"Edit in classic editor"** button. It reopens that product in the classic editor for that page load only — edit, save (your unadapted AJAX panel works as usual), and after saving the product returns to the block editor. Nothing is stored: the switch lives only in the URL. While in the classic editor a **"Switch to block editor"** button is available too. This works in both strategies (bridge and classic).

= My variable products show issues in Gutenberg. Can I keep them in the classic editor? =

Yes. Switch to the classic fallback with `define( 'EBEFWCP_MODE', 'classic' );` (or the `ebefwcp_mode` filter). Variable products then edit in the classic editor while non-variable products stay in Gutenberg.

= Does it add database tables, options or REST endpoints? =

No. The plugin stores nothing of its own and adds no REST endpoints; it only re-triggers WooCommerce's native save.

== Changelog ==

= 1.0.0 =
* First release.
* Per-product "Edit in classic editor" button on the product edit screen: a temporary, no-storage escape hatch for AJAX panels that have not been adapted to the block editor. Save and the product returns to the block editor.

= 0.3.0 =
* Bridge strategy (default) keeps Gutenberg on all products and re-triggers WooCommerce's native variation save on the Gutenberg save cycle.
* Classic strategy (fallback) routes variable products to the classic editor.
* Extensible saver framework with a public `window.ebefwcp.registerSaver()` API and PHP filters/actions.

== Upgrade Notice ==

= 1.0.0 =
First release.

= 0.3.0 =
Adds the bridge/classic strategies and the extensible saver framework.
