WooCommerce: Edit Add to Cart Min, Max & Step Quantity

Yes, there are many plugins that already achieve this. But my goal at Business Bloomer is to save you from plugin conflicts, delicate updates and to make you learn some PHP ๐Ÿ™‚

So, here’s how you can add, with a few lines of PHP, a minimum, maximum, increment and starting value to your Add to Cart quantities on the single product and cart pages. Who knew it was this easy?

WooCommerce Min/Max, Increment and Start Value Add to Cart Quantities

PHP Snippet 1: Set Min, Max, Increment & Start Value Add to Cart Quantity @ WooCommerce Single Product Page & Cart Page (Simple Products)

/**
 * @snippet       Min, Max, Increment & Start Value Add to Cart Quantity | WooCommerce
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @testedwith    WooCommerce 4.5
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */
 
add_filter( 'woocommerce_quantity_input_args', 'bloomer_woocommerce_quantity_changes', 10, 2 );
  
function bloomer_woocommerce_quantity_changes( $args, $product ) {
  
   if ( ! is_cart() ) {
 
      $args['input_value'] = 4; // Start from this value (default = 1) 
      $args['max_value'] = 10; // Max quantity (default = -1)
      $args['min_value'] = 4; // Min quantity (default = 0)
      $args['step'] = 2; // Increment/decrement by this value (default = 1)
 
   } else {
 
      // Cart's "min_value" is already 0 and we don't need "input_value"
      $args['max_value'] = 10; // Max quantity (default = -1)
      $args['step'] = 2; // Increment/decrement by this value (default = 0)
      // COMMENT OUT FOLLOWING IF STEP < MIN_VALUE
      // $args['min_value'] = 4; // Min quantity (default = 0)
 
   }
  
   return $args;
  
}

PHP Snippet 2: Set Min Add to Cart Quantity @ WooCommerce Single Product Page (Variable Products -> Single Variation)

/**
 * @snippet       Min Add to Cart Quantity for Variations | WooCommerce
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @testedwith    WooCommerce 4.5
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */
 
add_filter( 'woocommerce_available_variation', 'bloomer_woocommerce_quantity_min_variation', 9999, 3 );

function bloomer_woocommerce_quantity_min_variation( $args, $product, $variation ) {
	$args['min_qty'] = 5;
	return $args;
}

Where to add this snippet?

You can place PHP snippets at the bottom of your child theme functions.php file (delete "?>" if you have it there). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such files - if you need more guidance, please take a look at my free video tutorial "Where to Place WooCommerce Customization?"

Does this snippet (still) work?

Please let me know in the comments if everything worked as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting on PHP 7.3.

If you think this code saved you time & money, feel free to join 14,000+ WooCommerce Weekly subscribers for blog post updates or 250+ Business Bloomer supporters for 365 days of WooCommerce benefits. Thank you in advance :)

Need Help with WooCommerce?

Check out these free video tutorials. You can learn how to customize WooCommerce without unnecessary plugins, how to properly configure the WooCommerce plugin settings and even how to master WooCommerce troubleshooting in case of a bug!

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza.

75 thoughts on “WooCommerce: Edit Add to Cart Min, Max & Step Quantity

  1. Dont work on products Home front page —

    1. Hi Anderson, what do you use to display products on the home page?

  2. Hi
    thanks for this great code.
    but this code dosent work for woocommerce add_to_cart ajax button.
    do you have any solution for this problem.

    1. Hi Sajad, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  3. Hey =)
    I would like to use a direct Add-to-Cart link on my salespage to skip the shopping cart. I am using the following link: https://www.mydomain.com/checkout/?add-to-cart=19 (product ID is 19).

    It works fine but the problem is that if the buyer clicks on this link several times, for every click another product gets added in the checkout. For example if the buyer clicks on the link twice the quantity on the checkout page will be 2.

    Is it possible to restrict this so that even when the buyer clicks several times on the link the quantity will be 1?

    But the buyer should still be able to adjust the quantity on the checkout page manually.

    1. You could disable click after the first click (jQuery)

  4. Helloo, Thank you Rodolfo for the awesome post. it works but i have an issue. the – and + button only increment or reduce by one then doesn’t work. but if i type the number myself i can add it to card. would this be a theme issue ? they’re not answering me. if you have any idea where i could fix that it would be amaazing. Thank you

    1. Default Woo has no + – buttons

  5. Hi Rodolfo,

    Thanks for your awesome code snippets!

    I implemented the code exactly as per snippet 1 and have this issue:

    Single product page
    The + and – buttons stop at the min and max value and step correctly. However, the user can still just type a qty and press ‘Add to cart’. No validation warnings show and the user can enter any value included outside the min and max range. The qty is added to the cart and the user can checkout – eg selecting 3 units.

    Cart page
    Validations show when the user types the qty and presses Update and has entered an invalid option.

    Should the validations also work on the single product page?

    1. Hi Nick, I get validation errors when I try to add to cart from the single product page: validation on the single product page

  6. Hello
    Can we add min order quantity according to the country region?
    Thanks

    1. Akshay, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  7. When I select swatched options it returns to 1 and goes up by the step I set up in this code. have you checked that?

    1. Not sure I fully understand

  8. Hi,
    thanks for your blog, source of inspiration!
    I created this snippet, it works well in the product pages but not in the cart, what could I change?
    thanks a lot

     add_filter( 'woocommerce_quantity_input_args', 'bb_woocommerce_quantity_input_args', 10, 2 ); // Simple products
    
    function bb_woocommerce_quantity_input_args( $args, $product ) {	
    	  if ( has_term( '72', 'product_tag' )  ) {
    		$args['input_value'] 	= 72;
    	$args['max_value'] 	= 1584; 	// Maximum value
    	$args['min_value'] 	= 72;   	// Minimum value
    	$args['step'] 		= 72;    // Quantity steps
    } else if ( has_term( '36', 'product_tag' ) ) {	
    		$args['input_value'] 	= 36;
    	$args['max_value'] 	= 180; 	// Maximum value
    	$args['min_value'] 	= 36;   	// Minimum value
    	$args['step'] 		= 36	;    // Quantity steps
      } 
    
       
       return $args;
       
    }
    
    1. Hi Pasquale, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  9. How can i change the steps in the cart only for a specific item in the category downloads. So when i have more products and one in the category Downloads. How can I change the steps quantity only for that product?

    1. Winsley, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  10. Hi Rodolfo,
    thank you so much for this snippet.
    Is it posible to exclude single products?

    1. Hi Uli, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  11. Actually, it works.
    Thanks

    1. Thank you!

  12. Hi there, i think your job it’s amazing and i wonder if u can help me.

    I added the quantity buttons in the loop page (and I made, work 100%), now I want to restrict the numbers and the step it’s not possible for me because instead of 1-2-3-4-5-6-7-8-9 i want to do 1-2-3-4-6-12-18-24

    Thanks

    1. Hello Wilson, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  13. I need to set the default quantity box add to cart number to 0, is it possible?

    The quantity selector shows 1, and people won’t add to cart the tickets.

    We need the opc quantity selector to be set with 0, so that the customers understand that they have to select the quantity and click ADD TICKETS (in spanish, “aรฑadir localidades”).

    Is it possible to set 0 as default selection in the quantity box?

    1. Hello Mario, thanks so much for your comment! Did you try setting the min to 0? Anyway, this is possible – unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding! ~R

  14. Hi, how do I add a variable?
    $args[‘min_value’] = the_field(‘minimum_order’); ???????

    1. Hey Alex, thanks so much for your comment! Yes, this is possible – unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  15. Hi there!

    Thanks for this great tutorial!

    Quick question โ€“ is it possible to only target grouped products? In my WooCommerce store simple products already have their default quantity values set to ‘1’, but I’d like it to be ‘1’ as well for grouped products and also make it a minimum of ‘1’ for each product within the grouped product. Hope that makes sense ๐Ÿ™‚

    Thanks!

    1. Hello Jonas, thanks so much for your comment! Yes, this is possible – unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  16. Hi,

    I want t set this up for individual products, and have them start at 5 or 2.

    However, users are able to hit the minus – and go down from 5 to 1 so there is no set MIN quantity it only starts at that number.

    Cheers,

    1. Hello Matt, thanks for your comment! Not sure I fully understand, but either way this snippet still works, I just tested it.

  17. Hi, I want this function for my specific product id. Please help me how can I use this function for specific product only.

    1. Hey Anas, thanks for your comment! I suggest you take a look at “conditional logic”: https://businessbloomer.com/conditional-logic-woocommerce-tutorial/ and https://businessbloomer.com/woocommerce-conditional-logic-ultimate-php-guide/. Let me know ๐Ÿ™‚

  18. Works like a charm ๐Ÿ™‚
    wp 4.9.8
    storefront 2.3.5

    Thanks Rodolfo

    1. Awesome ๐Ÿ™‚

  19. Hello Rodolfo.
    Is there any way to leave minimum and maximum value undefined? My eshop has different min. values for every product. I would like to set just step value.
    Thanks.
    xtrmntr

    1. Hey there, thanks for your comment! Have you tried using the following:

       = ''; 
  20. Hi Rodolfo,
    the code works fine when adding to cart, but once on the cart one can easily change the quantity and set them lower than required. That is due to the !is_cart(), I imagine. If I remove that condition then strange things happen on the cart, such as the quantity going back to minimum after recalculating (but the total would be correct). E.g.:
    If minimun is 10 and the price is 1$ I could set it to Q=20 and after recalculating it would show a total of 20$, but Q back to 10, which is very confusing for the visitor.
    How to solve it, please?

    1. Hello Franco, I just tested the code and it works wonderfully on both Cart and Single Product. And also when you “update Cart”. So please try using a different theme for testing e.g. Storefront or 2017, and deactivate all plugins.

      The only thing is this – if “min” is greater than “step” (e.g. step = 2 and min = 4) everything works on the single product page but you can indeed select a lower quantity on the Cart (2 in this case), which is not acceptable. However, the Cart item minimum quantity must be 0, so this creates a little problem. Let me look into it… I’ll reply here soon

      1. Snippet updated with an extra line in the Cart section. You won’t be able to set quantity = 0 in the Cart, but you still have the “Remove Item” button. Hope this helps!

    2. Oh yes, it works. I had made some mistakes due to some added complexity in order to set different min values for specific products. Great work ๐Ÿ™‚

      1. ๐Ÿ™‚

  21. Thank you so much!!! Incremental quantities plugin had conflicts with all the “Hide the price until login” plugins i could find and your solution works with them! Big help!

    1. Great ๐Ÿ™‚

  22. Hi

    I have a probleme with this code, it put the default quantiti also to the cart (warenkorb). i have definde as default 6, and i i change it to 5 it shows in the cart 6 as quantiti, but the total value is correct. so the user has change ist again.

    WP 4.9.1
    Woocommerce 3.2.6

    1. Hi, i found a better solution on docs.woocommerce.com

      // Simple products
      add_filter( ‘woocommerce_quantity_input_args’, ‘jk_woocommerce_quantity_input_args’, 10, 2 );

      function jk_woocommerce_quantity_input_args( $args, $product ) {
      if ( is_singular( ‘product’ ) ) {
      $args[‘input_value’] = 2; // Starting value (we only want to affect product pages, not cart)
      }
      $args[‘max_value’] = 80; // Maximum value
      $args[‘min_value’] = 2; // Minimum value
      $args[‘step’] = 2; // Quantity steps
      return $args;
      }

      // Variations
      add_filter( ‘woocommerce_available_variation’, ‘jk_woocommerce_available_variation’ );

      function jk_woocommerce_available_variation( $args ) {
      $args[‘max_qty’] = 80; // Maximum value (variations)
      $args[‘min_qty’] = 2; // Minimum value (variations)
      return $args;
      }

      1. Thanks so much ๐Ÿ™‚

  23. Rodolfo, thank you for this helpful snippet! How would I specify a maximum quantity (for one particular product in the store) based on cart total, e.g. one allowed per $10 in cart?

    1. Dan, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  24. Hi Rodolfo,

    A really useful add-on that set me to thinking … my website will have 2 user roles – retail and wholesale. I would like to have the unit of sale for a retail user as 1, and the unit of sale for a wholesale user as 6. Could a condition be added to this snippet such that it would only work for a wholesale user. The increment would be 6 if a wholesale user was logged in but only 1 if not?

    Many thanks

    1. Hello there, thanks so much for your comment! I suggest you take a look at “conditional logic”: https://businessbloomer.com/conditional-logic-woocommerce-tutorial/ and https://businessbloomer.com/woocommerce-conditional-logic-ultimate-php-guide/. Let me know ๐Ÿ™‚

  25. Hey Rodolfo, I implemented the snippet, using input value = 100, and step = 100.
    It starts fine, but when I click on the quantity increment button (I’m testing in Chrome), it increments like this: 100 > 101 > 201 > 301 > …
    Then when I decrement: 301 > 201 > 101 > 1
    It should be 100 > 200 > 300… / 300 > 200 > 100 > 0
    Anyone else with this phenomenon?
    Thank You so much!

    1. Pretty weird Peter ๐Ÿ™‚ Can you try with a different theme and no extra plugins?

    2. I am having exactly the same issue…..? Was there ever a solution posted?

      Such a sweet piece of code! just climbs in increments of what I set +1

      e.g. 1000 is 1001 and not 100 like specified

  26. Dear Rodolfo,

    I tried your snippet and it works great on product page.
    If I visit cart page total value is fine, but qty. didn’t changed there and it starts with my input value 100:
    $args['input_value'] = 100;

    It would be nice if somebody else can confirm this bug.

    Also it would be good to expand this snippet so that we can target products in categories.

    Great work. Keep going and cheers ! ๐Ÿ™‚

    1. Hey Danijel, thanks for your comment! Could you try with a different theme and no plugins please?

    2. I use enfold and there was only woocommerce installed. However I solve this with the similar snippet I found on Woocommerce website. I just change “product_cat” into “product_tag”. Both solutions work fine, but in my situation version with “product_tag” is better, because I don’t want to use more then 1 category per product, and I need those categories for SEO.

      function jk_woocommerce_quantity_input_args( $args, $product ) {
      if (( has_term('10', 'product_tag', $product->post ) ) ) {
      $args['step'] = 10;
      $args['min_value'] = 10;
      return $args;
      }
      else if (( has_term('100', 'product_tag', $product->post ) ) ) {
      $args['step'] = 100;
      $args['min_value'] = 100;
      return $args;
      }
      else {
      $args['step'] = 1;
      $args['min_value'] = 1;
      return $args;
      }
      }

  27. Hi Rodolfo, this updates the quantity but doesn’t correspondingly update the price

    1. Jonathan, thanks for your comment! Are you 100% sure? Can you try with another theme for a moment?

  28. Hi Rodolfo,
    I got the same as Nicolas, the min works fine but the max limit can be trespassed. Using WP 4.8 and woocommerce 3.1.0. Any suggestion?
    Regards

    1. I’ve tried this on WP 4.8, Woo 3.1.0 – on the single product page the “plus minus” is indeed blocked at the value I set in the snippet. what does not work is if you add to cart the max, and then go back to the product and add to cart again. It will add more quantity and not restrict that. Is this the problem?

  29. Hello Rodolpho !

    The site and your teaching are excellent in general ! Keep going !
    About this snippet, it works for me, except for the max quantity…. i can still select + 10 items and add them to the cart.

    Woocommerce version: 2.6.14 (maybe it will works on the updated woocommerce ?)

    1. Hey Nicolas, thanks for your comment! Yes, please, test it on the latest version and let me know ๐Ÿ™‚

  30. Rodolfo, thank you for sharing this snippet!

    I’ve tried it and it does a great job, but unfortunately it changes *all* the products in my store. Is there a way to customize it so it only affects specific products?

    Thank you for all the help!

  31. It is a cool snippet, but actually doesnt work.

    1. Melanie, thanks for your comment! Are you use this doesn’t work? It worked perfectly during my test – see blog post image ๐Ÿ™‚ Let me know

  32. Hi there, great snippet!

    But is there a way to make this effective only for a specific product or category (since is_product / is_category conditions cannot be run into functions.php?

    Tnx a lot!

    1. Thank you Alessandro. Yes this is absolutely possible, and you can run is_product() in functions.php, not sure where you got that from ๐Ÿ™‚ I suggest you take a look at “conditional logic”: https://businessbloomer.com/conditional-logic-woocommerce-tutorial/ and https://businessbloomer.com/woocommerce-conditional-logic-ultimate-php-guide/. Let me know ๐Ÿ™‚

  33. Hi,

    With the Add Min, Max, Increment & Start Value @ Add to Cart Quantity | WooCommerce Single Product Page, is it possible to do this for different products. I have several different products, all of which have different quantity minimums, maximums and steps.

    Thank You

    1. Hey Haris, thanks for your comment! Yes, this is possible of course. I suggest you take a look at “conditional logic”: https://businessbloomer.com/conditional-logic-woocommerce-tutorial/ and https://businessbloomer.com/woocommerce-conditional-logic-ultimate-php-guide/. Let me know ๐Ÿ™‚

    2. Hello! I’m very new to this, so please have mercy ๐Ÿ˜‰
      But I read through so many search results now and tried so much to get it to work, but just can’t.

      I want to limit the restricted quantities just to some products (those with a certain tag). So the closest (I think) I came was this:

      add_filter( 'woocommerce_quantity_input_args', 'bloomer_woocommerce_quantity_changes', 10, 2 );
        
      function bloomer_woocommerce_quantity_changes( $args, $product ) {
        
      if( $product->is_product_tag( 'example' )) {
         $args['input_value'] = 5;
         $args['max_value'] = 100; 
         $args['min_value'] = 3; 
         $args['step'] = 1;
        }
      
         return $args;
       
      }
      

      Unfortunatly it’s not working ๐Ÿ™

      Pleast help me out! Thanks!

      1. Hey David, according to https://businessbloomer.com/woocommerce-easily-get-product-info-title-sku-desc-product-object/, you can get the product tag IDs with:

        $product->get_tag_ids();
        

        After that, with a PHP foreach you can loop through the IDs to see if your tag ID is in there ๐Ÿ™‚

        Hope this helps!

Questions? Feedback? Support? Leave your Comment Now!
_____

If you are writing code, please wrap it between shortcodes: [php]code_here[/php]. Failure to complying with this (as well as going off topic, not writing in English, etc.) will result in comment deletion. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining BloomerArmada to get blog comment reply priority, ask me 1-to-1 WooCommerce questions and enjoy many more perks. Thank you :)

Your email address will not be published.