WooCommerce: How to Fix Can’t Pay for Order Because “Out of Stock” Error

WooCommerce Ninja

In some WooCommerce setups, customers who select an offline payment (like Cash on Deliver or Check/Cheque) and then change their mind and go into the order to pay for it using an online method find that they are unable to pay for their pending order because it says the item is out-of-stock.

They would receive the following message when attempting to make payment:

“Sorry, (product) is no longer in stock so this order cannot be paid for. We apologize for any inconvenience caused.”

When the customer placed their order, the item’s inventory count was decreased appropriately from 1 to 0.  This is obviously a bug in WooCommerce since the item should not need to be in stock in order for the customer to pay for their order.

The Code to Fix “Can’t Pay for Order Because Out of Stock”

In order to fix this issue, place the following code into your theme’s functions.php file.

add_filter('woocommerce_pay_order_product_has_enough_stock', 'custom_woocommerce_pay_order_product_has_enough_stock', 10, 3);
add_filter('woocommerce_pay_order_product_in_stock', 'custom_woocommerce_pay_order_product_has_enough_stock', 10, 3);
function custom_woocommerce_pay_order_product_has_enough_stock( $is_in_stock, $product, $order ){
  if (
    $product->stock_status !== 'instock'
    && strpos($_SERVER['REQUEST_URI'], 'order-pay') !== false
    && $_GET['pay_for_order'] == 'true'
  ) {
    return true;
  return $is_in_stock;

How It Works

What this code does is hook into the WooCommerce function of checking to see if a product is in stock.  If if detects that you are on the order-pay URL, it overrides it to say that the product is in stock so that the customer may proceed with their payment.

Notify of

Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Matthew Willson
Matthew Willson
5 years ago

Thanks, really helped

4 years ago

Thanks for sharing the code, Nathan! However, it seems recent updates in WooCommerce brought the problem back. I thought it might be interference from another plugin. However, on a fresh install of WordPress 5.2.2 with WooCommerce 2.7.0 the code mentioned in the article doesn’t fix the problem anymore. I tried using the “woocommerce_pay_order_product_in_stock” filter instead but either my code is bad or it’s simply not the right way. Any ideas?

4 years ago

I’ve found WC order workflow to be frustrating in many ways in regards to payment and fulfillment being one combined process. These are separate on most other platforms. Looking for this same solution since I offer my customers payment terms, but code did not work for me. Any suggestions?

Marwan Khanfar
Marwan Khanfar
3 years ago

Is there an update on the issue, I’m experiencing it

2 years ago

Hello this code actually doesn’t work ! but i have a new code :

add_filter(‘woocommerce_pay_order_product_has_enough_stock’, ‘custom_woocommerce_pay_order_product_has_enough_stock’, 10, 3); add_filter(‘woocommerce_pay_order_product_in_stock’, ‘custom_woocommerce_pay_order_product_has_enough_stock’, 10, 3); function custom_woocommerce_pay_order_product_has_enough_stock( $product_stock,$product, $order ){ if($product->stock_status != ‘instock’ && strpos($_SERVER[‘REQUEST_URI’], ‘order-pay’) != false && $_GET[‘pay_for_order’] == ‘true’) { return true; } }

I use this but with one condition and custom order statu (reserved). this statu when is creat reduce the stock and after customer say ok i send a link of paiment and i change the reserved statu for reserved paiement. Before pay order i check statu reserved-paiement for more security.

3 months ago


Thank you for contribution.

This snippet not working with lastest woocommerce. Can you update it ?