隐藏“删除项目”从购物车中WooCommerce中的特定产品 [英] Hide "remove item" from cart for a specific product in WooCommerce
本文介绍了隐藏“删除项目”从购物车中WooCommerce中的特定产品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在为我的网站使用woocommerce,我想为一个特定的商品隐藏删除该商品/产品,请告诉我该怎么做。
I'm using woocommerce for my website, I want to hide "remove this item/product" for one particular item, can you please tell me how can I do so.
非常感谢您对此提供的帮助。
I would greatly appreciate any help towards this.
推荐答案
已更新(适用于多种产品)数组中的ID)
Updated (for multiple product Ids in an array)
此处是禁用/删除删除此项目按钮的正确方法,对于其中的特定产品ID(您应定义)下面的代码:
Here is the correct way to disable/remove the "Remove this item" button, for a specific product ID (that you should define) in the code below:
add_filter('woocommerce_cart_item_remove_link', 'customized_cart_item_remove_link', 20, 2 );
function customized_cart_item_remove_link( $button_link, $cart_item_key ){
//SET HERE your specific products IDs
$targeted_products_ids = array( 25, 22 );
// Get the current cart item
$cart_item = WC()->cart->get_cart()[$cart_item_key];
// If the targeted product is in cart we remove the button link
if( in_array($cart_item['data']->get_id(), $targeted_products_ids) )
$button_link = '';
return $button_link;
}
代码位于活动子主题的function.php文件中(或活动主题)。
经过测试并有效。
这篇关于隐藏“删除项目”从购物车中WooCommerce中的特定产品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文