1

I know that the question of limiting each user to 1 comment per post has been asked a million times and I have read them all so please bear with me.

I am trying to limit Woocommerce reviews per order per user and the WC review system uses the WP comments system. Out of the box Woocommerce allows a buyer to review the same product unlimited times which is stupid. None of the other questions I can find are using hooks, they are directly hacking the review form template like this: One comment per user email per post

I would like to hook into the WC review form and only display if the user/buyer has not already left a review for that product. Here's what I have so far:

function sjs_review_check( $review_form ) {
    global $current_user, $post;

$usercomment = get_comments(array('user_id' => $current_user->ID,'post_id' => $post->ID) ); 

if (! $usercomment) {
  return $review_form;
    }
}
add_filter( 'woocommerce_product_review_comment_form_args', 'sjs_review_check' );

This code partially works, it successfully checks if the user has commented before and if so it hides the "Your Rating" section of the review form where the user selects a 1-5 star rating. But the "Your Review" text input box remains visible and working. I think maybe the code is disabling the WC review form which is then defaulting back to the WP form.

Anyone got any ideas or has anyone already figured out what action/filter disables the entire review form?

0

If anyone is interested the issue was indeed that the review form was reverting to the WordPress comment form when disabled so the same code needed to be applied to both forms.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.