Removing link from product thumbnail on cart page

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.

Solution 1:

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):

add_filter( 'woocommerce_cart_item_permalink', '__return_false' );

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:

if ( ! $product_permalink ) {
    echo $thumbnail; // PHPCS: XSS ok.
} else {
    printf( '<a href="%s">%s</a>', esc_url( $product_permalink ), $thumbnail ); // PHPCS: XSS ok.
}

by:

echo $thumbnail;

You are done. The product link is now removed from the thumbnail.