WooCommerce:仅在某些类别页面上显示添加到购物车按钮

发布于 2025-02-13 08:51:04 字数 365 浏览 1 评论 0原文

在WooCommerce中,我的functions.php文件中有一些很棒的代码,该文件将“添加到购物车”按钮在主商店页面中的产品下方。就是这样:

add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 20 );

太好了!但是我现在将一些产品更改为可变产品,它说“选择选项”下面的产品。

我可以更改此代码,以便它仅在页面上显示某些类别的产品吗?

换句话说,主商店页面具有可变产品(无需添加到卡车按钮),但是我也有类别页面显示简单的产品,这些产品按照上述代码显示在卡车按钮上。

非常感谢!

In Woocommerce, I have some great code in my functions.php file which puts an "add to cart" button underneath the products in the main shop page. This is it:

add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 20 );

That's great! But I'm now changing some products to variable products and it says "select options" underneath instead.

Can I alter this code so that it only displays on a page showing products from certain categories?

In other words, the main shop page has the variable products (no add to cart buttons), but I also have category pages showing simple products which display the add to cart buttons as per the code above.

Many thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

三生殊途 2025-02-20 08:51:04

您将使用条件标签从特定产品类别中删除操作,因为默认情况下已显示。

is_product_category()

确保在添加之前使用钩子发射的钩子。

You would remove the action from specific product categories using a conditional tag as its already displayed by default.

is_product_category()

Make sure you use a hook which fires before its added.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文