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

问题描述

我想禁用特定可变产品的购物车商品和订单商品名称中的链接。

我找到了 Disable item name link for specific product in Woocommerce cart checkout and orders 答案代码,该代码确实禁用了单个产品上的链接,但我想知道如何为一个变量更改它?

解决方法

以下内容将适用于所有产品类型(简单,可变,变化...),并禁用定义的产品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',3 );
function conditionally_remove_cart_item_permalink( $permalink,$cart_item['variation_id']) ) ) {
        $permalink = '';
    }
    return $permalink;
}

// Order item link
add_filter( 'woocommerce_order_item_name','conditionally_remove_link_from_order_item_name',2 );
function conditionally_remove_link_from_order_item_name( $item_name,$item ) {
    // HERE set your products IDs in the array
    $product_ids = array(37,array($item->get_product_id(),$item->get_variation_id()) ) ) {
        $item_name = $item->get_name();
    }
    return $item_name;
}

代码进入活动子主题(或活动主题)的functions.php文件中。经过测试,可以正常工作。

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...