In addition. You already have code which can kind of do what you need.
add_filter( 'preprocess_comment', 'verify_comment_meta_data' );
function verify_comment_meta_data( $commentdata ) {
if ( ! isset( $_POST['wp_review_comment_rating'] ) )
wp_die( __( 'A rating is required. Hit the BACK button and resubmit your review with a rating.' ) );
// this is filter and $commentdata has comment_type parameter in it. so you need to do this
$commentdata['comment_type'] = 'wp_review_comment';
return $commentdata;
}
This will do what you wanted but now all your newly created comments will become this type of wp_review_comment
, so if you need them the other way – you’ll need some kind of conditionals in this filter instead of forcing all comments to have wp_review_comment_rating
and forcing them to be wp_review_comment
type or die(), preventing from saving.
See https://core.trac.wordpress.org/browser/tags/5.3/src/wp-includes/comment.php#L1874 for more details