Zum Inhalt springen

Automatic stock restoration

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

WooCommerce reduces stock when an order becomes "Processing", "On hold" or "Completed". It puts the stock back itself when the order is cancelled, but not when the status changes to "Refunded": goods you refunded still count as sold. This module puts them back automatically and makes sure nothing is restocked twice.

Go to Polski > Modules and enable Auto Restore Stock in the "Stock & Cart" section. The module is off by default and has no settings of its own.

From status To status Module checks the order
Processing Cancelled Yes
Completed Cancelled Yes
On hold Cancelled Yes
Processing Refunded Yes
Completed Refunded Yes
On hold Refunded Yes
Processing Failed Yes
On hold Failed Yes

Other changes, for example from "Pending payment" to "Cancelled", are skipped. The stock of such an order has usually not been reduced yet.

  1. The order goes through one of the transitions in the table.
  2. The module checks the WooCommerce option Enable stock management. When it is off, nothing happens.
  3. For every line item whose product manages stock, it reads the _reduced_stock marker. WooCommerce stores in it how much it reduced that line, and deletes it when it restocks the line itself.
  4. A line with the marker goes back into stock by the stored quantity and the marker is removed. A line without the marker is skipped.
  5. Every restored line adds an order note, for example "Stock restored: T-shirt (5 -> 8)".
  6. When anything was restored, the order gets the _polski_stock_restored meta and is marked as an order whose stock is no longer reduced.

On cancellation WooCommerce usually restocks first and clears the markers, so the module has nothing left to restore. That is why stock never comes back twice.

A customer bought 3 items, the order is "Completed" and the product stock is 5. The customer sends the goods back, you refund the money and set the status to "Refunded". The module raises the stock to 8 and adds the note "Stock restored: T-shirt (5 -> 8)". Any later status change of that order does not change stock again.

  • The WooCommerce option Enable stock management (WooCommerce > Settings > Products > Inventory) must be on.
  • Products must have stock management enabled.
Hook Type Arguments When
polski/stock/restored action WC_Product $product, WC_Order_Item_Product $item, WC_Order $order After one line item is restocked
add_action('polski/stock/restored', function ($product, $item, $order) {
// For example: push the stock change to an external warehouse.
}, 10, 3);

No. The module restores only lines that still carry the _reduced_stock marker and removes it afterwards. An order with the _polski_stock_restored meta is skipped entirely.

What about refunding part of an order?

Section titled "What about refunding part of an order?"

The module reacts to a status change of the whole order. A partial refund without changing the status to "Refunded" is handled by WooCommerce: in the refund dialog you choose to put the refunded items back into stock.

Does the module act on "Pending payment" orders?

Section titled "Does the module act on "Pending payment" orders?"

No. The stock of such orders has usually not been reduced yet, so there is nothing to restore.