How to enable Out of Stock message when quantity input exceeds stock levels?
-
Hello,
Is there a way for me to display a message saying “Max quantity reached” or “Sorry we do not have enough quantity in stock”?
In Cart, when user tries to click the “+” button, nothing changes. I’d like to display an error message to inform the user that they cannot exceed that number.
I’ve had a look through the code and this feature is there, but does not seem to be working. Stock management feature is enabled for all products.
I do not want to enable backorders, nor do I want to set max/min levels manually.
// We only need to check products managing stock, with a limited stock qty. if ( ! $product->managing_stock() || $product->backorders_allowed() ) { continue; } // Check stock based on all items in the cart and consider any held stock within pending orders. $held_stock = ( $hold_stock_minutes > 0 ) ? wc_get_held_stock_quantity( $product, $current_session_order_id ) : 0; $required_stock = $product_qty_in_cart[ $product->get_stock_managed_by_id() ]; if ( $product->get_stock_quantity() < ( $held_stock + $required_stock ) ) { /* translators: 1: product name 2: quantity in stock */ $error->add( 'out-of-stock', sprintf( __( 'Sorry, we do not have enough "%1$s" in stock to fulfill your order (%2$s available). We apologize for any inconvenience caused.', 'woocommerce' ), $product->get_name(), wc_format_stock_quantity_for_display( $product->get_stock_quantity() - $held_stock, $product ) ) ); return $error; } } return true; }
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘How to enable Out of Stock message when quantity input exceeds stock levels?’ is closed to new replies.