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.
Advertisement
Answer
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
Updated: Added a hooked function to handle minicart
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; }
Code goes in functions.php file of your active child theme (or active theme). Tested and works.