簡體   English   中英

在 WooCommerce 購物車結帳和訂單中禁用特定產品的項目鏈接

[英]Disable item link for specific products in WooCommerce cart checkout and orders

我想禁用特定可變產品的購物車商品和訂單商品名稱的鏈接。

在 Woocommerce 購物車結帳和訂單答案代碼中找到了禁用特定產品的項目名稱鏈接,該代碼確實禁用了單個產品上的鏈接,但我想知道如何將其更改為變量之一?

以下將適用於所有產品類型(簡單、可變、變體……),從定義的產品 ID數組中禁用項目鏈接:

// Cart item link
add_filter( 'woocommerce_cart_item_name', 'conditionally_remove_link_from_cart_item_name', 10, 3 );
function conditionally_remove_link_from_cart_item_name( $item_name, $cart_item, $cart_item_key ) {
    // HERE set your products IDs in the array
    $product_ids = array(37, 40);

    if( array_intersect($product_ids, array($cart_item['product_id'], $cart_item['variation_id']) ) ) {
        $item_name = $cart_item['data']->get_name();
    }
    return $item_name;
}

// Mini-cart item link
add_filter( 'woocommerce_cart_item_permalink', 'conditionally_remove_cart_item_permalink', 10, 3 );
function conditionally_remove_cart_item_permalink( $permalink, $cart_item, $cart_item_key ) {
    // HERE set your products IDs in the array
    $product_ids = array(37, 40);

    if( array_intersect($product_ids, array($cart_item['product_id'], $cart_item['variation_id']) ) ) {
        $permalink = '';
    }
    return $permalink;
}

// Order item link
add_filter( 'woocommerce_order_item_name', 'conditionally_remove_link_from_order_item_name', 10, 2 );
function conditionally_remove_link_from_order_item_name( $item_name, $item ) {
    // HERE set your products IDs in the array
    $product_ids = array(37, 40);

    if( array_intersect($product_ids, array($item->get_product_id(), $item->get_variation_id()) ) ) {
        $item_name = $item->get_name();
    }
    return $item_name;
}

代碼進入您的活動子主題(或活動主題)的functions.php 文件。 測試和工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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