Home » WooCommerce: Edit Add to Cart Default, Min, Max & Step Product Quantity

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

by Tutor Aspire

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 tutoraspire.com FREE
 * @author        Tutor Aspire
 * @testedwith    WooCommerce 6
 * @donate $9     https://www.tutoraspire.com
 */
 
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 

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 tutoraspire.com FREE
 * @author        Tutor Aspire
 * @testedwith    WooCommerce 6
 * @donate $9     https://www.tutoraspire.com
 */
 
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;
}

You may also like