Hi @joelmellin
I tried and was able to load 15 quantities of a product to cart, but when I checked the cart it was empty. It seems that items not getting added to cart needs to be addressed before stopping adding quantity depending on stock.
Here’s an article that may help: https://www.boiseweb.net/articles/why-a-woocommerce-product-wont-add-to-the-cart-with-fixes/
As for setting the maximum limit per product so that it doesn’t exceed the stock availability, you can use the Min and Max Quantity for WooCommerce plugin. You can read more on it here: https://storepro.io/learn/how-to-set-minimum-and-maximum-order-quantity-in-woocommerce/#set-min-and-max-quantity-with-min-and-max-quantity-for-woocommerce-plugin-free
For any queries you may have about the plugin, feel free to open a topic here: https://wordpress.org/support/plugin/minmax-quantity-for-woocommerce/
I hope this helps!
Hi!
The problem is not that the cart was empty when you tried to add 15 units, because it should not be possible if the stock is less than 15. The problem I have is that you could try to add 15 units. I want the number to automatically stop at maximum stock so that it is not even possbible to try to add more than there is in stock.
This has worked before, but now it doesn’t. The plugin you gave a link for does not fix that problem, I tried it but there is no option for that.
-
This reply was modified 3 years, 11 months ago by
joelmellin.
-
This reply was modified 3 years, 11 months ago by
joelmellin.
Hi @joelmellin,
Thank you for providing more details. Do you allow backorders?

Link to image: https://i.imgur.com/Sy3YfyZ.png
If you allow them, your customers can enter any number in the quantity box and it will be accepted. Instead, if you do not allow backorders, and your customer tries to enter a quantity over the allowed stock they should get a warning:

Link to image: https://i.imgur.com/Af8uMkm.png
Let us know if this helps.
No we do not allow back orders.
Earlier the counter (that is marked with a red triangle in the attached picture) would automatically stop at the maximum stock when pushing the + button. But now it doesn’t.
Picture
It seems like this part of the code is not working anymore:
function woa_woocommerce_quantity_input_args( $args, $product ) {
if ( is_singular( ‘product’ ) && $product->is_type( ‘simple’ ) && $product->is_purchasable() && $product->is_in_stock() && ! $product->is_sold_individually() ) {
$args[‘input_value’] = 1; // Starting value (we only want to affect product pages, not cart)
}
$args[‘max_value’] = $product->get_stock_quantity; // Maximum value
$args[‘min_value’] = 0; // Minimum value
$args[‘step’] = 1; // Quantity steps
return $args;
}
-
This reply was modified 3 years, 11 months ago by
joelmellin.
Hello,
I recommend debugging the code to check it will work according to your needs. That way you can make sure the condition on the code is working as expected or if it needs some adjustment.
To learn more about debugging please refer to:
* https://woocommerce.com/document/woocommerce-product-search/api/debugging/
* https://developer.woocommerce.com/testing-extensions-and-maintaining-quality-code/debugging-tools/
I hope this helps.
We haven’t heard back from you in a while, so I’m marking this thread as resolved – we’ll be here if and/or when you are ready to continue.