簡體   English   中英

在Woocommerce 3中隱藏購物車中特定產品的數量字段

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM