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

Remove Add To Cart button from certain category Woocommerce

Here i discuss How to Remove add to cart button from certain category in woocommerce. To do so, First from backend of website i have created two categories named as cat1 and cat2.

After that i assign some products to these categories. Product1 and Product2 has been assigned to cat1 category and Product3 has been assigned to cat2 category. Now, Add this following line of code in your theme’s functions.php file of your active child theme (or theme) and Save the file.

Now, You can see that add to cart button has been removed from this cat1 category page.

Now if you’ll go to cat2 category page, you’ll notice add to cart button hasn’t been removed for this category.

function wp_custom_buy_buttons(){

   $product = get_product();

   if ( has_term( 'cat1', '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', 'wp_custom_buy_buttons' );
Exit mobile version