禁用Woocommerce购物车结帐和订单中特定产品的商品名称链接 [英] Disable item name link for specific product in Woocommerce cart checkout and orders

查看:73
本文介绍了禁用Woocommerce购物车结帐和订单中特定产品的商品名称链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望禁用指向购物车中特定产品的产品页面的产品链接。此产品是当购物车小计金额等于特定值时自动添加到购物车的礼品产品。

I'm looking to disable the product link to the product page of a specific product in the cart. This product is a gift product automatically added to the cart when the cart subtotal amount equals a particular value.

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

I know it's possible to do this with all the cart items. But I'm not quite sure on how to target a specific item.

推荐答案


新答案适用于所有产品类型,适用于一系列已定义的产品ID,在这里:

在WooCommerce购物车结帐和订单中禁用特定产品的商品链接

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

已更新: 添加了一个钩子函数来处理微型购物车

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

To remove the item name link from cart, checkout and orders, use the following:

// 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文件中。经过测试,可以正常工作。

Code goes in functions.php file of your active child theme (or active theme). Tested and works.

这篇关于禁用Woocommerce购物车结帐和订单中特定产品的商品名称链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆