comments_open is used for both post types, posts and products, the snippet below worked and allowed only (example) role users to comment
enter code here
add_action( 'init', function(){
$u = wp_get_current_user();
if( $u->exists() && in_array( 'example', (array) $u->roles, true ) ) return; add_filter( 'comments_open', '__return_false' );} );
But it also made the product reviews appear only for (example) role users and other roles cannot review products. I have tried modifying the snippet to remove post_type =='product' from the rule
enter code here add_action( 'init', function() {$u = wp_get_current_user();
if( $u->exists() && in_array( 'example', (array) $u->roles, true ) OR $post->post_type == 'product' ){return;} add_filter( 'comments_open', '__return_false' );} );
But still, other roles cannot review products, only (example) role users can, how do I do this? Thank you in advance