在Woocommerce 3中隐藏购物车中特定产品的数量字段 [英] Hide quantity fields in cart for specific products in Woocommerce 3
问题描述
我想在购物车页面中的一个特定产品类别中隐藏数量字段.
I Would like to hide the quantity field from one specific product category in cart page.
单独出售"对我没有帮助,因为我有一个必须禁用才能正常工作的插件.
The "Sold Individually" doesn't help me because I have a plugin that must be disabled to work.
有可能吗?任何曲目将不胜感激.
Is it possible? Any track will be appreciated.
推荐答案
以下代码将隐藏购物车页面上的产品数量字段:
The following code will hide the product quantity field on cart page:
1)特定产品类别(您将在此代码中定义):
add_filter( 'woocommerce_quantity_input_args', 'hide_quantity_input_field', 20, 2 );
function hide_quantity_input_field( $args, $product ) {
// Here set your product categories in the array (can be either an ID, a slug, a name or an array)
$categories = array('t-shirts','shoes');
// Handling product variation
$the_id = $product->is_type('variation') ? $product->get_parent_id() : $product->get_id();
// Only on cart page for a specific product category
if( is_cart() && has_term( $categories, 'product_cat', $the_id ) ){
$input_value = $args['input_value'];
$args['min_value'] = $args['max_value'] = $input_value;
}
return $args;
}
代码进入活动子主题(或活动主题)的function.php文件中.经过测试和工作.
它还将处理添加到购物车中的产品变体.
Code goes in function.php file of the active child theme (or active theme). Tested and works.
It will also handle product variations added to cart.
2)用于特定产品ID (您将在此代码中定义):
2) for specific product IDs (that you will define in this code):
add_filter( 'woocommerce_quantity_input_args', 'hide_quantity_input_field', 20, 2 );
function hide_quantity_input_field( $args, $product ) {
// Here set your product IDs in the array
$product_ids = array(37,40,70);
// Handling product variation
$the_id = $product->is_type('variation') ? $product->get_parent_id() : $product->get_id();
// Only on cart page for a specific product category
if( is_cart() && in_array( $the_id, $product_ids ) ){
$input_value = $args['input_value'];
$args['min_value'] = $args['max_value'] = $input_value;
}
return $args;
}
代码进入活动子主题(或活动主题)的function.php文件中.经过测试和工作.
它还将处理添加到购物车中的产品变体.
Code goes in function.php file of the active child theme (or active theme). Tested and works.
It will also handle product variations added to cart.
这篇关于在Woocommerce 3中隐藏购物车中特定产品的数量字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!