How to set minimum and maximum product quantities in WooCommerce?

Photo of author
Written By geekerhub

Lorem ipsum dolor sit amet consectetur pulvinar ligula augue quis venenatis. 

To change the maximum and minimum quantities of the products, one needs to use the filters provided by WooCommerce.

Below are the filters which are related to the quantity selector field:

  • woocommerce_quantity_input_min
  • woocommerce_quantity_input_max

woocommerce_quantity_input_min filter allows to change the minimum value for the quantity. The default value for the minimum quantity is 0.

woocommerce_quantity_input_max filter allows changing the maximum value for the quantity. The default value for the minimum quantity is -1.

/*Woocommerce min input quantity filter : woocommerce_quantity_input_min*/
<?php
/*
* Changing the minimum quantity to 1 for all the WooCommerce products
*/
function woocommerce_quantity_input_min_callback( $min, $product ) {
  $min = 1;  
  return $min;
}
add_filter( 'woocommerce_quantity_input_min', 'woocommerce_quantity_input_min_callback', 10, 2 );
?>
/*Woocommerce max input quantity filter : woocommerce_quantity_input_max*/
<?php
/*
* Changing the maximum quantity to 2 for all the WooCommerce products
*/
function woocommerce_quantity_input_max_callback( $max, $product ) {
  $max = 2;  
  return $max;
}
add_filter( 'woocommerce_quantity_input_max', 'woocommerce_quantity_input_max_callback', 10, 2 );
?>

Leave a Comment