WooCommerce – Remove “Add To Cart” From A Product Page

By default there is not option in WooCommerce settings to disable, delete or remove the ‘Add To Cart’ button from a specific category or a product page. In this tutorial we will learn how to disable the “Add-To-Cart” button in a specific category of products and on that specific product page as well which is assigned in that particular WooCommerce product category. Let’s do this!

1. First step is to create a new products category in WooCommerce that you will assign to single product or multiple products on which you do not want to display the add to cart button.

2. Once you have created the category, now assign all those products in that category on which you don’t to show add to cart.

3. Once you are done with aforementioned steps, now go to your dashboard >> Appearance >> editor and open the functions.php file.

4. Go to the bottom of your themes’s functions file and add the code provided below:

function chiefthemes_remove_addcart() {
   $product = get_product();
   if ( has_term ( 'category-name', 'product_cat') ) {
       remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart' );
       remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
       remove_action( 'woocommerce_simple_add_to_cart', 'woocommerce_simple_add_to_cart', 30 );
       remove_action( 'woocommerce_grouped_add_to_cart', 'woocommerce_grouped_add_to_cart', 30 );
       remove_action( 'woocommerce_variable_add_to_cart', 'woocommerce_variable_add_to_cart', 30 );
       remove_action( 'woocommerce_external_add_to_cart', 'woocommerce_external_add_to_cart', 30 );
   }
}
add_action( 'wp', 'chiefthemes_remove_addcart' );

5. Make sure you replace the ‘category-name‘ in line 3 of the code above, with the category you created in step 1.

That’s pretty much it! Now every new product you will create that is assigned in this category will not show the add to cart button, and rest of the products in other categories will show it.

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *