Automatically fill and limit the minimum quantity of a product in Woocommerce

0

Well, someone knows how to set the minimum quantity of a product (to add to the cart) by setting the quantity according to the Woocommerce Minimum Quantity setting.

For example, we have some products registered in Woocommerce being some products like "Variable product", in the variations tab there are some variables and for some products we must set the minimum quantity of purchase by filling in the field Minimum Quantity.

When I access the product page to insert it into the shopping cart the input is not coming with the minimum quantity set in the variant.

Is it possible that on the product page you have already set the input of the quantity of 30, for example, and do not let buy (insert in the cart) with less quantity than this?

I've been able to set the minimum quantity for all products and all variants, but that's not what I need, but it's automatic to set the Minimum Quantity.

add_filter( 'woocommerce_quantity_input_args', 'ex_woocommerce_quantity_input_args', 10, 2 );

function ex_woocommerce_quantity_input_args( $args, $product ) {
    if ( is_singular( 'product' ) ) {
        $args['input_value'] = 25;
    }
    $args['min_value'] = 25; // Minimum value
    return $args;
}

add_filter( 'woocommerce_available_variation', 'ex_woocommerce_available_variation' );

function ex_woocommerce_available_variation( $args ) {
    $args['min_qty'] = 25;  
    return $args;
}

It was with this code that I was able to leave all products and all variants with a minimum of 25, but I do not want this, I need to come automatic from the minimum quantity field.

    
asked by anonymous 13.04.2018 / 15:13

0 answers