How to set product quantity, minimum value and increment amount in Woocommerce?

In this tutorial, We’ll learn how to set initial quantity, minimum value, maximum value and increment amount for products in woocommerce.

Default values are:

Quantity => 1
 
Minimum Value => 1
 
Maximum Vale => Any Quantity
 
Increment Amount => 1
 
We can change one to all of these values. To do this add the following lines of code at the end of your theme’s functions.php file:
 
add_filter( 'woocommerce_quantity_input_args', 'jk_woocommerce_quantity_input_args', 10, 2 );
 
function jk_woocommerce_quantity_input_args( $args, $product ) {
 
   $args['input_value']    = 2;         // Starting value
 
   $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;
 
}

You can access functions.php file here;

woocommerce

First function is for simple products and second for variable products. Every array field is self-explanatory and you can change that to any value you want.

Now if you add product to cart from archive page and go to cart page you’ll see initial quantity i.e. 2.

woocommerce

woocommerce

On the product page, initial quantity will be set.

woocommerce

And if you enter the quantity less than minimum quantity or greater than maximum quantity, you’ll see a notice to change quantity accordingly.

That is all for now.

CHEERS J

Waqas

I hope you enjoy reading this blog post. If you want my team to do WooCommerce Maintenance for you, click here.

4 thoughts on “How to set product quantity, minimum value and increment amount in Woocommerce?”

  1. Here is the Solution for You.

    add_action( ‘woocommerce_check_cart_items’, ‘woocommerce_check_cart_quantities’
    );

    function woocommerce_check_cart_quantities() {

    $multiples = 250;

    $total_products = 0;

    foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {

    $total_products += $values[‘quantity’];

    }

    So it basically does the math of Number of Increments x Base value, so in my
    case 12 x 250 = 3000.
    This value is carried to the Cart and the price is also corrected. Works well
    with dynamic pricing as well.

  2. Hello guys!
    Thank you for the great tutorial!
    I have one question though, and it is about the add to cart quantities:
    I am wondering, is it possible to have multiple options when adding quantities as shown here:
    http://www.squattypotty.com/shop/product/refresh-it-bidet/
    So first button would be 1, second 2 and third option would be to enter quantity manually where first option would be 3 or more (if added manually).
    Thanks in advance!

Leave a Comment

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