How can I remove the link (but keep theproduct thumbnail image) fromthe following code
<?php
$thumbnail = apply_filters( 'woocommerce_cart_item_thumbnail', $_product->get_image(), $cart_item, $cart_item_key );
if ( ! $product_permalink ) {
echo $thumbnail; // PHPCS: XSS ok.
} else {
printf( '<a href="%s">%s</a>', esc_url( $product_permalink ), $thumbnail ); // PHPCS: XSS ok.
}
?>
It is part of the Woocommerce cart.php. I want to keep the link for the product name, but remove it from the thumbnail.
2
Answers
To remove the product permalink from each cart item, simply use the following into the functions.php file of your active child theme (or active theme):
Tested and works.
If you want to remove the product link only from the thumbnail in cart page use the following:
First read “Template structure & Overriding templates via a theme” official documentation to understand how to Override WooCommerce templates via the active child theme (or active theme).
Once you have copied the template cart/cart.php into your theme as explained before, open edit it and replace the lines:
by:
You are done. The product link is now removed from the thumbnail.
The OP asks about how to remove the link from the product thumbnail on the cart page. The first solution from the LoicTheAztec answer will remove the link both from the product thumbnail and product title, that is great, but even if it is necessary, it is too much.
The second solution of the LoicTheAztec answer, implying a template override, is too complex for this. Less difficult is to add a second filter, in addition to the first solution, that will add back the link only to the product titles.
Tested and works.