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 3.8
 * @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 3.8
 * @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;
}
Share:

Leave a Reply