[英]Hide quantity fields in cart for specific products in Woocommerce 3
我想隱藏購物車頁面中某一特定產品類別的數量字段。
“單獨出售”對我沒有幫助,因為我有一個必須禁用才能運行的插件。
可能嗎? 任何軌道將不勝感激。
以下代碼將隱藏購物車頁面上的產品數量字段:
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文件中。 經過測試和工作。
它還將處理添加到購物車中的產品變化。
2)對於特定的產品ID (您將在此代碼中定義) :
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文件中。 經過測試和工作。
它還將處理添加到購物車中的產品變化。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.