仅在 woocommerce 商店/类别页面上隐藏“添加到购物车"按钮 [英] Hide 'add to cart' button ONLY on woocommerce shop/category pages

查看:53
本文介绍了仅在 woocommerce 商店/类别页面上隐藏“添加到购物车"按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想隐藏我的商店页面上的按钮,但我想在其他帖子和页面上显示它.

I want to hide the button on my shop pages, but I would like to show it on other posts and pages.

我发现这段代码可以隐藏整个网站上的添加到购物车按钮:

I've found this code to hide the add to cart button on my whole website:

add_action( 'woocommerce_after_shop_loop_item', 'remove_add_to_cart_buttons', 1 );

function remove_add_to_cart_buttons() {
    remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart' );
}

我该如何调整它,让它只删除 woocommerce 商店和分类页面上的按钮?

How can I tweak it, so it only removes the button on woocommerce shop and catagory pages?

推荐答案

您可以使用 Woocommerce 条件标签来检查:http://docs.woothemes.com/document/conditional-tags/>

You can use the Woocommerce conditional tags to check: http://docs.woothemes.com/document/conditional-tags/

   add_action( 'woocommerce_after_shop_loop_item', 'remove_add_to_cart_buttons', 1 );

    function remove_add_to_cart_buttons() {
      if( is_product_category() || is_shop()) { 
        remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart' );
      }
    }

这篇关于仅在 woocommerce 商店/类别页面上隐藏“添加到购物车"按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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