woocommerce Case study
Corporate Products Off Button
Our catalog carries company-stock items: products a supplier lists as available while our own quantity is zero. This utility takes those products offline in controlled batches, with a backup taken first and a restore button in case the decision turns out wrong.
The business problem
A company-stock product is one with a stock quantity of zero, empty or null while its stock status still reads in stock, regardless of whether stock management is switched on for it. That is not a filter the WooCommerce admin can express, so identifying the set was manual, and switching hundreds of products by hand has no undo. The risk was not the edit but the absence of a way back.
What I delivered
- a2-company-stock-off-rollback.php, an admin tool at version 1.3.0 with its own page rather than a bulk action, because the operation deserves a screen that explains what it is about to do.
- A backup written before any product is modified, and a rollback that restores the previous state from it.
- Batch processing with the job state stored in an option, so a run that exceeds a request can resume rather than leaving the catalog half-modified.
- An explicit definition of company stock in code, so the set being modified is auditable rather than a matter of whoever built the filter that day.
- Nonce protection on every action, since this is a tool that changes availability across a whole catalog.
Technical approach
- Backup before mutate, with rollback as a first-class feature rather than a manual database restore. On an operation this broad, the undo path is the feature.
- Job state lives in an option and is processed in batches, so PHP timeouts produce a resumable run instead of a partially updated catalog with no record of where it stopped.
- The company-stock definition is written once in the source and used by both the preview and the run, so what you are shown is exactly what will be changed.
- It is a dedicated admin page, not a bulk action in the product list, because a bulk action is one misclick away from being applied to the wrong selection.
Result and evidence
The operation became routine and reversible. Switching company-stock availability is now a run with a preview and a rollback rather than an afternoon of manual edits nobody wanted to be responsible for.
Commercial value
Bulk catalog operations are where small stores lose days. Making this one safe to repeat is what turned it from an incident risk into an ordinary task.
Readable implementation brief
implementation_brief {
project: "Corporate Products Off Button"
file: "mu-plugins/a2-company-stock-off-rollback.php (v1.3.0)"
target_set: "stock qty 0/empty/null AND status = instock,
regardless of manage_stock"
order: "backup -> batch mutate -> rollback available"
job_state: "stored in an option; run is resumable"
surface: "dedicated admin page, not a bulk action"
guard: "nonce on every action"
}What this project shows
The rollback is the reason this tool exists. Anyone can write a batch update; whether you can undo it is what decides if the team will use it under pressure.
Making it resumable rather than fast was the right trade. A run that stops halfway and can continue is far better than one that finishes quickly most of the time.