I want to remove the "Add to cart" Button on every page except the cart itself.
I found a solution to remove the cart button with an hook:
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
Works fine but that removes the button everywhere.
I tried this code to remove the button everywhere but the cart:
if (!is_cart()) :
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
endif;
But that doesn’t seem to work.
Is there any other way without touching a template file?
2
Answers
Did you try if isn’t cart?
The following will do the trick (based on
woocommerce_template_loop_add_to_cart()
original function code):Code goes in functions.php file of your active child theme (or active theme). Tested and works.
Related: Remove "Add To Card" only Home page in WooCommerce