I have an issue how to remove a cart from a category product. It works just fine if I apply it to a specific id or all in general, but I am unable to do it for a category. Below is my code I have done regarding it.
Also, I am struggling to apply this same pattern to Related Articles section, so any help would be appreciated.
Thank you.
//function for deleting ....
function remove_product_description_add_cart_button(){
global $product;
//Remove Add to Cart button from product description of product with id 1234
if ($product->id == 188){
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
}
add_action('wp','remove_product_description_add_cart_button');
}
Go to Appearance -> Customize, then go to WooCommerce -> Add to Cart Buttons to choose your settings. Change the Add To Cart button text and/or select the other options on this screen.
To do this, please navigate to the Dashboard > Installed Plugins page. Furthermore, find the WooCommerce section and select the Deactivate option then the cart icon will be instantly deleted from your website.
Nov 2020 Update
To make it work with a product category you can use the WordPress conditional function has_term()
this way:
add_action('woocommerce_single_product_summary', 'remove_product_description_add_cart_button', 1 );
function remove_product_description_add_cart_button() { // function for deleting ...
// Set HERE your category ID, slug or name (or an array)
$categories = array('your-category-1');
//Remove Add to Cart button from product description of product with id 1234
if ( has_term( $categories, 'product_cat', get_the_id() ) ) {
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
}
}
Code goes in function.php file of your active child theme (or active theme). Or also in any plugin php file. Tested and works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With