在 WooCommerce 购物车结帐和订单中禁用特定产品的项目链接 [英] Disable item link for specific products in WooCommerce cart checkout and orders

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

问题描述

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

I would like to disable the link from cart items and order items names for specific variable products.

我发现在 Woocommerce 购物车结帐和订单中禁用特定产品的项目名称链接 答案代码会禁用单个产品上的链接,但我想知道如何为变量更改它一个?

I found Disable item name link for specific product in Woocommerce cart checkout and orders answer code that does disable links on single product, but I would like to know how to change it for a variables one?

推荐答案

以下内容将适用于所有产品类型(简单、可变、变体……),禁用数组中的项目链接>定义的产品 ID:

The following will work with all product types (simple, variable, variations…), disabling item links from an array of defined product Ids:

// 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 文件中.经测试有效.

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

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

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