从购物车页面上的产品缩略图中删除链接 [英] Removing link from product thumbnail on cart page

查看:53
本文介绍了从购物车页面上的产品缩略图中删除链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从以下代码中删除链接(但保留产品缩略图)

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.

推荐答案

要从每个购物车商品中删除产品固定链接,只需将以下内容用于您的活动子主题的functions.php文件中(或活动主题):

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.

如果您只想从购物车页面的缩略图中删除产品链接,请执行以下操作:

首先阅读> 模板结构和通过主题覆盖模板" 官方文档,以了解如何通过活动子主题(或活动主题)覆盖WooCommerce模板.

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

按照之前的说明将模板cart/cart.php模板复制到您的主题后,打开对其进行编辑并替换以下行:

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.
}

作者:

echo $thumbnail;

您完成了.产品链接现在已从缩略图中删除.

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

这篇关于从购物车页面上的产品缩略图中删除链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆