Skip to content
Advertisement

Hide ‘add to cart’ button ONLY on woocommerce shop/category pages

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' );
}

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

Advertisement

Answer

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' );
      }
    }
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement