=== Stock Control for WooCommerce ===
Contributors: oacstudio, conschneider
Tags: stock, inventory, woocommerce, bulk edit, stock log
Requires at least: 6.5
Tested up to: 7.0
Requires PHP: 7.4
Stable tag: 1.1.0
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Edit the stock of all your WooCommerce products on one screen, and keep a log of every stock change.

== Description ==

Stock Control adds two things to your store:

**Stock Overview** (Products > Stock Overview) - one table with every product and variation. Edit stock quantity, low stock threshold, stock status, backorders and "Manage stock?" inline, then save a single row or all checked rows at once. No more opening every product one by one.

**Stock Log** (Products > Stock Log) - every stock change is recorded: who changed it (orders and automated changes show as "System"), the new stock values and when it happened. Entries for deleted products stay in the log.

All changes are written through the WooCommerce product API, so lookup tables, caches and variable-product syncing behave exactly as if you had saved the product edit screen.

**Settings** (WooCommerce > Settings > Stock Control):

* Disable inventory management on the parent of variable products, so stock is only managed per variation.
* Automatically delete log entries older than X days.
* Delete all log entries with one click.

Both screens are available to shop managers and administrators.

== Installation ==

1. Upload `stock-control.zip` to the `/wp-content/plugins/` directory, or install the plugin through the WordPress plugins screen directly.
2. Activate the plugin through the 'Plugins' menu in WordPress.
3. Navigate to Products > Stock Overview to start editing.
4. Navigate to Products > Stock Log to view stock log entries.

== Frequently Asked Questions ==

= Which stock changes are logged? =

Everything that goes through WooCommerce's stock hooks: edits made on the Stock Overview screen, the product edit screen, other plugins, and automatic changes such as order stock reduction. Changes without a logged-in user (orders, cron, API) show "System" as the user.

= Why does the stock status jump back when "Manage stock?" is checked? =

That is WooCommerce core behavior: while stock is managed, WooCommerce derives the status from the quantity and the backorder setting on every save (the product edit screen hides the status field entirely in that case). The Stock Overview greys the status dropdown out for managed rows. Uncheck "Manage stock?" to set the status by hand.

= Who can use the screens? =

Users with the `manage_woocommerce` capability - shop managers and administrators.

= Does it work with High-Performance Order Storage (HPOS)? =

Yes. The plugin only touches products, never orders, and declares HPOS compatibility.

= Are variations supported? =

Yes. Variations appear as their own rows on the Stock Overview, and variation stock changes are logged.

= Does deleting the plugin remove its data? =

Deactivating keeps everything. Deleting the plugin (uninstall) drops the stock log table and removes all plugin options.

== Screenshots ==

1. Stock Overview - edit stock for every product and variation on one screen.
2. Stock Log - every stock change with user and timestamp.
3. Settings - parent inventory toggle, automatic log purge, delete all entries.

== Changelog ==

= 1.1.0 =
* Security: the stock save endpoint now requires the `manage_woocommerce` capability. In 1.0.0 any logged-in user could change stock data. The AJAX credentials are also no longer printed on every admin page, only on the Stock Overview screen.
* Fix: the scheduled log purge never deleted anything (the query targeted a placeholder table name) and its setting was missing. The "Delete log entries after X days" setting is back and the daily purge works.
* Fix: stock edits are saved through the WooCommerce product API instead of raw post meta. Product lookup tables, caches and variable-product syncing now stay correct - in 1.0.0 stock filters, sorting and the REST API could show stale values after a save.
* Fix: variation stock changes made outside the plugin were never logged (the variation hook was missing).
* Fix: log entries for deleted products no longer disappear from the Stock Log; they show as "#ID (deleted)".
* Fix: searching on the Stock Overview showed "0 items" and broke pagination; search now also survives switching pages on both screens.
* Fix: two requests to non-existent front-end asset files on every page load of the site (leftover enqueues, 404s) - the plugin no longer loads anything on the front end.
* Fix: the "Disable inventory management for parent variable products" setting never worked (its JavaScript referenced the wrong object) and is now applied on the product edit screen.
* Fix: stock status and backorder values are validated against WooCommerce's allowed values before saving.
* Fix: script cache busting was broken (version constant mismatch).
* Fix: variations that inherit stock management from their parent product no longer show the parent's quantity as their own. In 1.0.0, saving such a row converted the variation to self-managed stock seeded with the parent's full quantity - bulk-saving could multiply sellable stock. Inheriting rows now show an "(inherits parent stock)" hint and an unedited save changes nothing.
* Fix: the "Products per page" / "Logs per page" screen options were never saved (the filter was registered after WordPress consumes it).
* Fix: saving a row without changes no longer writes anything, including no log entry.
* Fix: deactivating the plugin now removes its scheduled purge event.
* Fix: network activation on multisite creates the log table on every site, and uninstall cleans up every site.
* Improvement: the stock status dropdown is greyed out while "Manage stock?" is checked, matching how WooCommerce derives the status on save.
* Improvement: the JavaScript messages on the Stock Overview are translatable, and the Product Type column shows WooCommerce's translated labels.
* Improvement: the Stock Log shows "System" for stock changes without a user (orders, cron, API) and links products to their edit screen.
* Improvement: bulk save reports completion after all rows have actually saved, including a failure count.
* Improvement: the plugin screens are available to shop managers (`manage_woocommerce`), no longer administrators only.
* Housekeeping: WooCommerce dependency declared (`Requires Plugins`), HPOS compatibility declared, uninstall now removes the log table and all options, minimum versions WordPress 6.5 / PHP 7.4 / WooCommerce 9.5, indexes added to the log table.

= 1.0.0 =
* Initial release.

== Upgrade Notice ==

= 1.1.0 =
Security release: the stock save endpoint was usable by any logged-in user. Also fixes the log purge, variation logging, search, and front-end 404s.
