Turn Off Reviews for a Product Category
Disables reviews on products in chosen categories, such as made-to-order or services, while every other product keeps its Reviews tab.
Opens WPIDE on
Code
$wpide_no_review_cats = array( 'services', 'bespoke' ); // Category slugs.
add_filter( 'comments_open', function ( $open, $post_id ) use ( $wpide_no_review_cats ) {
return ( $open && 'product' === get_post_type( $post_id ) && has_term( $wpide_no_review_cats, 'product_cat', $post_id ) ) ? false : $open;
}, 20, 2 );
add_filter( 'woocommerce_product_tabs', function ( $tabs ) use ( $wpide_no_review_cats ) {
global $product;
if ( $product instanceof WC_Product && has_term( $wpide_no_review_cats, 'product_cat', $product->get_id() ) ) {
unset( $tabs['reviews'] );
}
return $tabs;
}, 98 );
Notes
Existing reviews are kept in the database but hidden along with the tab.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.