WooCommerce:仅在某些类别页面上显示添加到购物车按钮
在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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将使用条件标签从特定产品类别中删除操作,因为默认情况下已显示。
确保在添加之前使用钩子发射的钩子。
You would remove the action from specific product categories using a conditional tag as its already displayed by default.
Make sure you use a hook which fires before its added.