
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 descreased 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_product_is_in_stock', 'make_in_stock_when_paying_for_order', 10, 2); function make_in_stock_when_paying_for_order($instock_this_get_stock_status, $instance) { if($instock_this_get_stock_status != 'instock' && strpos($_SERVER['REQUEST_URI'], 'order-pay') != false && $_GET['pay_for_order'] == 'true') { return 'instock'; } return $instock_this_get_stock_status; }
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.

Blogger, expert WordPress developer, and developer of the awesome bbPress Voting plugin which is a must-have plugin for any bbPress forum.
Download bbPress Voting for free on the WordPress Plugin Directory.
Thanks, really helped
Great, I’m glad I could help.
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?
Gion,
I’m sorry to hear that the problem started occurring again.
I suggest you jump on this Github issue to let the WooCommerce team know you’re having this issue. https://github.com/woocommerce/woocommerce/issues/21796
Looks like someone else posted the same thing on there recently.
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?
Looks like this issue started happening again. You’re not the only one.
I suggest you jump on this Github issue to let the WooCommerce team know you’re having this issue. https://github.com/woocommerce/woocommerce/issues/21796
Looks like someone else posted the same thing on there recently.
Hello,
Is there an update on the issue, I’m experiencing it
Is this solution not working for you?
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.
@++