DEV Community

NextGen Fusion
NextGen Fusion

Posted on Originally published at nextgenfusion.in

WooCommerce Pending Orders Cancelled Automatically: Fix

If WooCommerce keeps cancelling orders that customers were still paying for, the cause is almost always one setting: "Hold stock (minutes)". By default WooCommerce cancels unpaid pending orders after 60 minutes, and it adds the order note "Unpaid order cancelled - time limit reached." If a customer's payment arrives late, through UPI, a bank page or a slow 3-D Secure step, the order may already be cancelled when the money lands.

This guide shows where the setting lives, why it catches real customers and how to change it without breaking your stock counts.

What the setting does

In the WooCommerce settings, under Products, then Inventory, you will find "Hold stock (minutes)". When the limit is reached, WooCommerce cancels the pending order. Leave the field blank to disable the timer. A fresh WooCommerce 11.3.1 installation showed 60 minutes with stock management enabled. See the WooCommerce inventory settings documentation.

Three details from the source code explain most of the confusion:

  1. It only runs when stock management is on. The scheduled job that cancels unpaid orders is set up only if "Enable stock management" is turned on and the hold time is 1 or more. If stock management is off, this is not what is cancelling your orders.
  2. It only touches orders created at the customer checkout. By default, only orders created through the classic checkout, the checkout block or the Store API are cancelled automatically. Orders created by an admin, the REST API or other plugins are not, unless a plugin changes that through the woocommerce_cancel_unpaid_order filter.
  3. The job runs on a schedule. WooCommerce uses its scheduled actions system (or WordPress cron as a fallback) to check for unpaid orders, so an order may be cancelled a little after the limit passes, not at the exact minute.

Why real customers get caught

A pending order is an order the customer has started but not yet paid for. The clock starts when the order is created. These legitimate cases take longer than you expect:

  • UPI approvals that wait for the customer to open another app.
  • Bank pages, one-time passwords and 3-D Secure steps that time out and are retried.
  • Payment methods that confirm later, such as bank transfer or a delayed notification.
  • A customer who leaves checkout open on their phone and comes back an hour later.

If the order is cancelled before the confirmation arrives, you can end up with a paid payment and a cancelled order. See Razorpay payment successful but WooCommerce order pending for how to confirm what actually happened.

Step 1: confirm that this is the cause

Open one affected order and read its notes. If you see "Unpaid order cancelled - time limit reached.", the hold-stock timer cancelled it. If the note says something else, such as a gateway failure or an admin user cancelling it, the cause is different.

Step 2: check the setting

Go to WooCommerce, Settings, Products, Inventory and read the "Hold stock (minutes)" value. Then check "Enable stock management" on the same page. If you see 60 and your customers regularly need longer, that is the explanation.

Step 3: choose the right number

Think about the slowest normal payment on your store, then add a margin.

  • Cards and wallets usually confirm in minutes, so 60 minutes is often enough.
  • If UPI collect requests or bank-transfer style methods are common, consider a longer hold.
  • If you sell limited stock, a long hold lets unpaid orders block other buyers. Balance the two.

Changing the value takes effect at the next scheduled run. You do not need to edit any code for this.

Step 4: decide what blank and zero do

The setting text says leaving it blank disables it. In the code, a hold time below 1 stops the job from being scheduled. That means unpaid orders stay in "Pending payment" forever and keep their stock held, so you will need to clean them up yourself. For most stores a longer limit is safer than disabling it.

Step 5: protect paid orders with a working webhook

A longer limit reduces the problem, but the real protection is a payment confirmation that reaches your store reliably. Use a gateway integration that updates the order from a verified server notification, not only from the customer's browser. If the confirmation arrives while the order is pending, it completes correctly, whatever the hold time. Check that your gateway's webhook is active and that the secrets match.

Step 6: recover orders that were cancelled but paid

  1. Check the payment in your gateway dashboard.
  2. If the money is captured, restore the order by changing its status from Cancelled to Processing.
  3. Check the stock level for each item, because cancelling returns stock to inventory, and restoring the order may need a manual adjustment.
  4. If an item has since sold out, contact the customer and offer an alternative or a refund.
  5. Add a note with the payment ID.

Step 7: make sure the schedule actually runs

If orders are never cancelled, even when you want them to be, the scheduled job may not be running. In the admin, WooCommerce, Status, Scheduled Actions lists pending, failed and completed actions. A long list of past-due actions means WordPress cron is not firing, often because DISABLE_WP_CRON is set without a real server cron, or because of a caching or security plugin blocking wp-cron.php. The opposite also happens: a cron burst after a quiet period cancels many orders at once.

Step 8: custom changes

Developers can adjust the behaviour with the filters mentioned in the WooCommerce code: woocommerce_cancel_unpaid_orders_interval_minutes changes how often the check runs, and woocommerce_cancel_unpaid_order decides whether a given order should be cancelled, for instance to protect orders for a particular payment method. Test any change on a staging copy first. Our guide to setting up a WordPress staging site shows how.

A quick checklist

  • Hold stock is long enough for your slowest normal payment.
  • Stock management is on only if you really track stock.
  • The gateway webhook is active, reachable and verified.
  • Pending orders are reviewed daily during sales.
  • Cancelled orders are checked against the gateway before you tell a customer they did not pay.

When to call a developer

If cancelled orders keep appearing with paid payments, if the scheduled actions list shows failures, or if you use a custom checkout or a payment method with special timing, the fix may need code: a filter to protect certain orders or a corrected webhook handler. Our WooCommerce payment integration and checkout troubleshooting covers these cases, and WooCommerce orders stuck on pending payment covers the opposite problem.

Frequently asked questions

What is the default hold time in WooCommerce?

A fresh WooCommerce 11.3.1 installation showed 60 minutes. Your store may have a different value if someone changed it.

Will cancelling restore my stock?

When an unpaid order is cancelled, its stock is released back to inventory, so other customers can buy it. If you restore a cancelled order, check the stock levels again.

Can I stop automatic cancellation for one payment method?

Yes, with code that uses the woocommerce_cancel_unpaid_order filter, or by choosing a longer hold time for all orders. Test it on staging first.

Why do admin-created orders not cancel?

By default, only orders created at the customer checkout are cancelled automatically. Orders created from the admin, the REST API or other plugins are not.

Is this the same as a failed payment?

No. A failed payment is reported by the gateway. This is a timer that cancels an order when no payment has been recorded in time.


Originally published on the NextGen Fusion blog.

Top comments (0)