如何解决禁用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文件中。经过测试,可以正常工作。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。