Home » woocommerce_quantity_input_max Filter

woocommerce_quantity_input_max Filter

  • by

woocommerce_quantity_input_max this filter using with function woocommerce_quantity_input() . woocommmerce quantity max and min using with filter. if you want to setup min and max qty adding in cart than this filter is much useful for you. woocommerce woocommerce_quantity_input max function using to give limit for it

How to work Woocommerce Quantity min and max

In theme of function.php you should be put woocommerce_quantity_input_max filter. if you want to use Code snippets than you can use that plugin

function woocommerce_quantity_input_max_callback( $max, $product ) {
$max = 5;
return $max;
}
add_filter( 'woocommerce_quantity_input_max', 'woocommerce_quantity_input_max_callback', 10, 2 );

There is $max = 5 there should be assign value of how much of max Quantity need to add. if you need to add max 10 qty than add $max = 10

If you need to setup particular Woocommerce product for need to setup max quantity than

add_filter( 'woocommerce_quantity_input_min', 'woocommerce_quantity_input_min', 10, 2 );
function woocommerce_quantity_input_min( $min, $product ){
if ( $product->get_id() == 108) {
$min = 2;
} else {
$min = 3;
}
return $min;
}

You need to just add if condition in that condition need to change product id

Filter defined in to following location(s).

/includes/wc-template-functions.php  
  1. ‘max_value’ => apply_filters( ‘woocommerce_quantity_input_max’, -1, $product ),
/templates/single-product/add-to-cart/grouped.php  
  1. ‘max_value’ => apply_filters( ‘woocommerce_quantity_input_max’, $grouped_product->get_max_purchase_quantity(), $grouped_product ),
/templates/single-product/add-to-cart/variation-add-to-cart-button.php  
  1. ‘max_value’ => apply_filters( ‘woocommerce_quantity_input_max’, $product->get_max_purchase_quantity(), $product ),
/templates/single-product/add-to-cart/simple.php  
  1. ‘max_value’ => apply_filters( ‘woocommerce_quantity_input_max’, $product->get_max_purchase_quantity(), $product ),

Related Action for this

woocommerce_quantity_input_classes
woocommerce_quantity_input_max
woocommerce_quantity_input_min
woocommerce_quantity_input_step
woocommerce_quantity_input_pattern
woocommerce_quantity_input_inputmode
woocommerce_quantity_input_args

Important Note:

If you need more powerful feature for this than you can be download Min Max Quantities For Woocommerce WordPress plugin there include user role, min and max qty as well category wise rustication you can be add. if you want to know How to Setup Min and Max Qty in Woocommerce  you can read that artical

Leave a Reply

Your email address will not be published.