Remove add to cart button on WooCommerce products that belong to a certain category
Here is some code to allow you to hide the Add to Cart button on WooCommerce products that belong to a certain category, so if the product page is viewed by a customer they will be unable to add the product to a cart. The code needs to be add to your themes functions.php file.
add_action( 'woocommerce_single_product_summary', 'remove_add_cart_button' );
/**
* Remove add to cart button
*/
function remove_add_cart_button() {
// Categories
$categories = array( 'uncategorized' );
if ( has_term( $categories, 'product_cat', get_the_id() ) ) {
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
}
}
So in the above any product that belongs to the ‘Uncategorized’ product category will have the add to cart button removed, you can add multiple categories comma separated to the array either as the name or category ID.