You can allow backorders, which will keep the product purchasable even without stock.
You can also use the in stock filter woocommerce_product_is_in_stock
to keep the product in stock when the customer is on the Pay page or needed times.
Hi Vankaa,
I tried enabling back-orders, but then the item shows as available for other customers to buy. I only want customers with a pending order (that I have created for them) to be able to purchase the items.
I don’t want to hide the items from my catalogue, as I need people to be able to see them.
I’m not sure how woocommerce_product_is_in_stock
works, but it sounds like it will create the same dilemma above, yes?
I did find the following code in class-wc-shortcode-checkout.php – would it be safe for me to simply remove it?
// Ensure order items are still stocked.
foreach ( $order->get_items() as $item_key => $item ) {
if ( $item && is_callable( array( $item, 'get_product' ) ) ) {
$product = $item->get_product();
if ( $product && ! $product->is_in_stock() ) {
/* translators: %s: product name */
throw new Exception( sprintf( __( 'Sorry, "%s" is no longer in stock so this order cannot be paid for. We apologize for any inconvenience caused.', 'woocommerce' ), $product->get_name() ) );
}
}
}
Kind regards,
Rebecca
I would not recommend removing core code. Instead go the
filter route and instead of always adjusting in stock status, do so on the Pay page, where this error message is actually checked and displayed.
To answer your question, though, yes, if you remove this part behavior will be the same as it was in previous version.
We haven’t heard back from you in a while, so I’m going to mark this as resolved. If you have any further questions, you can start a new thread.
@rebeccablackman, I ran into this exact same problem and developed a simple fix for it that uses the ‘woocommerce_product_is_in_stock’ hook (like @vankaa mentioned). Here it is…
https://wpforthewin.com/woocommerce-cant-pay-out-of-stock-error/
I hope you and others with the same problem find it helpful.