WooCommerce: Edit Add to Cart Default, Min, Max & Step Product 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 default value to your Add to Cart quantity input field 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 & Default Value Add to Cart Quantity @ WooCommerce Single Product Page & Cart Page (Simple Products)

/**
 * @snippet       Min, Max, Increment & Default Value Quantity | WooCommerce
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @testedwith    WooCommerce 8
 * @community     https://businessbloomer.com/club/
 */
 
add_filter( 'woocommerce_quantity_input_args', 'bloomer_woocommerce_quantity_changes', 9999, 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 {
 
      $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 8
 * @community     https://businessbloomer.com/club/
 */
 
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;
}

Advanced Plugin 1: WooCommerce Quantity Discounts, Rules & Swatches

If you’d love to code but don’t feel 100% confident with that, there are plugin alternatives.

Based on reputation, support quality, code cleanliness, long-term reliability, theΒ WooCommerce Quantity Discounts, Rules & Swatches pluginΒ by Studio Wombat is probably your best bet.

With an easy to understand settings panel you can enable tiered pricing,Β quantity swatches, min & max quantities, tooltips and multilingual support all from the same settings panel.

Advanced Plugin 2: WooCommerce Quantity Manager

In case you want another code-free solution, WooCommerce Quantity Manager may suit your needs as well.

This well-coded and fully-featured plugin has a full range of quantity management features. You can set the default quantity value to anything you like, including zero. There are also options to set quantity minimums, maximums, and step values.

Where to add custom code?

You should place custom PHP in functions.php and custom CSS in style.css of your child theme: where to place WooCommerce customization?

This code still works, unless you report otherwise. To exclude conflicts, temporarily switch to the Storefront theme, disable all plugins except WooCommerce, and test the snippet again: WooCommerce troubleshooting 101

Related content

  • WooCommerce: Custom Add to Cart URLs – The Ultimate Guide
    In WooCommerce you can add a product to the cart via a custom link. You just need to use the “add-to-cart” URL parameter followed by the product ID. This tutorial will show you how to create custom URLs to add simple, variable and grouped products to the cart – as well as defining the add […]
  • WooCommerce Visual Hook Guide: Single Product Page
    Here’s a visual hook guide for the WooCommerce Single Product Page. This is part of my “Visual Hook Guide Series“, through which you can find WooCommerce hooks quickly and easily by seeing their actual locations (and you can copy/paste). If you like this guide and it’s helpful to you, let me know in the comments! […]
  • WooCommerce: Disable Variable Product Price Range $$$-$$$
    You may want to disable the WooCommerce variable product price range which usually looks like $100-$999 when variations have different prices (min $100 and max $999 in this case). With this snippet you will be able to hide the highest price, and add a “From: ” prefix in front of the minimum price. At the […]
  • WooCommerce: Hide Price & Add to Cart for Logged Out Users
    You may want to force users to login in order to see prices and add products to cart. That means you must hide add to cart buttons and prices on the Shop and Single Product pages when a user is logged out. All you need is pasting the following code in your functions.php (please note: […]
  • WooCommerce: How to Fix the “Cart is Empty” Issue
    For some reason, sometimes you add products to cart but the cart page stays empty (even if you can clearly see the cart widget has products in it for example). But don’t worry – it may just be a simple cache issue (and if you don’t know what cache is that’s no problem either) or […]

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. Follow @rmelogli

77 thoughts on “WooCommerce: Edit Add to Cart Default, Min, Max & Step Product Quantity

  1. Hi Rodolfo

    The code snippet is working, but for the variations where I altered the min amount and incremental steps to 0.01, the add to cart is not working anymore. Any idea why?

    If I recall correctly, the default add to cart amount for WooCommerce is 1? Do I need to change that as well in order to make this work?

    Regards
    Pieter

  2. Dont work on products Home front page —

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

  3. 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!

  4. 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)

  5. 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

  6. 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

  7. 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!

  8. 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

  9. 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!

  10. 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!

  11. 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!

  12. Actually, it works.
    Thanks

    1. Thank you!

  13. 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!

  14. 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

  15. 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

  16. 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

  17. 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.

  18. 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 πŸ™‚

  19. Works like a charm πŸ™‚
    wp 4.9.8
    storefront 2.3.5

    Thanks Rodolfo

    1. Awesome πŸ™‚

  20. 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:

       = ''; 
  21. 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. πŸ™‚

  22. 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 πŸ™‚

  23. 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 πŸ™‚

  24. 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

  25. 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 πŸ™‚

  26. 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

  27. 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;
      }
      }

  28. 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?

  29. 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?

  30. 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 πŸ™‚

  31. 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!

  32. 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

  33. 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 πŸ™‚

  34. 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? Customization? Leave your comment now!
_____

If you are writing code, please wrap it like so: [php]code_here[/php]. Failure to complying with this, as well as going off topic or not using the English language will result in comment disapproval. 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 the Business Bloomer Club to get quick WooCommerce support. Thank you!

Your email address will not be published. Required fields are marked *