2

I have a variable product called flyer in woocommerce, and I want to set its default quantity input value to 500 as its min quantity. This is what I have done so far, but the default quantity is still 1.

add_filter( 'woocommerce_available_variation', 'jk_woocommerce_available_variation' ); // Variations
function jk_woocommerce_available_variation( $args ) {

    if( has_term('flyer') )

       $args['max_qty'] = 10000;        // Maximum value (variations)
       $args['min_qty'] = 500;
       $args['input_value']=500;

    return $args;
}

1 Answer 1

1

On woocommerce_available_variation hook the $args array doesn't include input_value argument.

Also You are not using has_term() conditional function in the right way for product categories.

So try the following code instead:

add_filter( 'woocommerce_available_variation', 'customizing_available_variation', 10, 3 ); // Variations
function customizing_available_variation( $args, $product, $variation ) {
    if( has_term( 'flyer', 'product_cat', $product->get_id() ) ) {
        $args['max_qty']     = 10000;        // Maximum value (variations)
        $args['min_qty']     = 500;
        // $args['input_value'] = 500; // This argument doesn't exist here
    }
    return $args;
}

add_filter( 'woocommerce_quantity_input_args', 'customizing_quantity_input_args', 10, 2 );
function customizing_quantity_input_args( $args, $product ) {
    if( $product->is_type('variable') && has_term( 'flyer', 'product_cat', $product->get_id() ) ) {
        $args['max_value']   = 10000; // Maximum value (variable product)
        $args['min_value']   = 500;
        $args['input_value'] = 500;
    }
    return $args;
}

Code goes in functions.php file of your active child theme (or active theme). Tested and works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.