Removing link from product thumbnail on cart page

家住魔仙堡 提交于 2021-01-24 11:55:10

问题


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.

回答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.



来源:https://stackoverflow.com/questions/57493110/removing-link-from-product-thumbnail-on-cart-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!