Site icon Experience Wordpress Developer Online – Design Develop and Maintenance Support

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

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. we will show you 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.

step 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.

step 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.

step 3. Once you are done with tha steps, Open your functions.php file of your active child theme (or theme) and add below code to it.

 function wpthemes_remove_addcart() {
   $product = get_product();
   //  replace the 'category-name' with your category slug which you want to hide.
   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', 'wpthemes_remove_addcart' );

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

See 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.

Exit mobile version