I have a store set up in WooCommerce that requires product quantity to increase in steps of 6. We set it up that way with a code that is dependant on each product slug individual slug. It works fine with single products but it breaks on variable products (adding a 7th item and then continuing to increse product quantity in steps of 6).
Here is my code:
add_filter( 'woocommerce_quantity_input_args', 'quantity_selected_number', 10, 2 );
function quantity_selected_number( $args, $product ) {
//global $product;
if ( ! is_cart() ) {
if ($product->get_slug()=="product-01-slug"){
$args['input_value'] = 6; // Start from this value (default = 1)
$args['max_value'] = 600; // Maximum quantity (default = -1)
$args['min_value'] = 6; // Minimum quantity (default = 0)
$args['step'] = 6; // Increment or decrement by this value (default = 1)
}
}
if ($product->get_slug()=="product-02-slug"){
// Cart's 'min_value' is 0
$args['input_value'] = 3;
$args['max_value'] = 260;
$args['step'] = 3;
$args['min_value'] = 3;
}
if ($product->get_slug()=="product-03-slug"){
// Cart's 'min_value' is 0
$args['input_value'] = 3;
$args['max_value'] = 260;
$args['step'] = 3;
$args['min_value'] = 3;
}
return $args;
}
Any idea why that is and what could make it work for variable products?
To handle product variation for variable products, you need an additional hooked function.
I have also added another function to handle Ajax add to cart.
Below I have revisited your code too as there were some little mistakes.
Try the following instead:
Code goes in functions.php file of your child theme (or in a plugin). Tested and works.
Related: Set quantity minimum, maximum and step at product level in Woocommerce