在 Woocommerce 购物车结账和订单中禁用特定产品的项目名称 link

Disable item name link for specific product in Woocommerce cart checkout and orders

我希望将产品 link 停用到购物车中特定产品的产品页面。本商品为赠送商品,当购物车小计金额达到特定值时自动加入购物车。

我知道可以对所有购物车商品执行此操作。但我不太确定如何定位特定项目。

New answer that works for all product types for an array of defined products Ids, here:
Disable item link for specific products in WooCommerce cart checkout and orders

更新: 添加了一个 hook 函数来处理 minicart

要从购物车、结帐和订单中删除商品名称 link,请使用以下命令:

// 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 Free product ID
    $gift_product_id = 37;
    
    if( $gift_product_id == $cart_item['data']->get_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 Free product ID
    $gift_product_id = 37;
    
    if( $gift_product_id == $cart_item['data']->get_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 Free product ID
    $gift_product_id = 37;

    if( $gift_product_id == $item->get_product_id() ) {
        $item_name = $item->get_name();
    }
    return $item_name;
}

代码进入您的活动子主题(或活动主题)的 functions.php 文件。已测试并有效。