admin管理员组文章数量:1303389
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;
}
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;
}
Share
Improve this question
edited May 22, 2019 at 16:07
rudtek
6,3535 gold badges30 silver badges52 bronze badges
asked May 22, 2019 at 14:49
mehdi lagmehdi lag
233 bronze badges
1 Answer
Reset to default 1On 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.
本文标签: Set a default quantity input value for a variable product category in WooCommerce
版权声明:本文标题:Set a default quantity input value for a variable product category in WooCommerce 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741670537a2391576.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论