将添加到购物车按钮替换为链接到 WooCommerce 3 商店页面上的产品页面的更多信息 [英] Replace add to cart button with a read more linked to product page on shop pages in WooCommerce 3

查看:27
本文介绍了将添加到购物车按钮替换为链接到 WooCommerce 3 商店页面上的产品页面的更多信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 woocommerce,但遇到以下问题:

I am using woocommerce and I have the following issue:

  • 产品与价格一起显示在主页上并添加到购物车按钮.
  • 添加到购物车按钮重定向到购物车页面.
  • 每个产品的图片都会重定向到产品页面.

重要的是让客户能够在将产品添加到购物车之前阅读产品描述.

An important thing is to allow customers to be able to read the description of the product before adding it to cart.

有没有办法用阅读更多"替换添加到购物车"按钮,以便从主页重定向到每个添加到购物车"按钮将出现的页面?

Is there a way to replace add to cart button with read more in order to redirect from homepage to each product's page where the add to cart button will appear?

推荐答案

通过链接到 woocommerce 3+ 的商店和存档页面中的产品替换按钮添加到购物车:

Replacing the button add to cart by a link to the product in Shop and archives pages for woocommerce 3+:

add_filter( 'woocommerce_loop_add_to_cart_link', 'replacing_add_to_cart_button', 10, 2 );
function replacing_add_to_cart_button( $button, $product  ) {
    $button_text = __("View product", "woocommerce");
    $button = '<a class="button" href="' . $product->get_permalink() . '">' . $button_text . '</a>';

    return $button;
}

代码位于活动子主题(或主题)的 function.php 文件或任何插件文件中.

此代码在 WooCommerce 3+ 上进行了测试并且可以正常工作.您可以自定义按钮的文本,您将得到如下内容:

This code is tested on WooCommerce 3+ and works. You can customize the text of button and you will get something like:

这篇关于将添加到购物车按钮替换为链接到 WooCommerce 3 商店页面上的产品页面的更多信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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