0

I am trying to hide the comments form if a user has left a comment on that particular post, otherwise display the comment form.

I added a code snippet to a hook which hides the form, but reverts to the WordPress comment form. I'm unable to figure out how to hide that form! I would also be open to hiding that entire column if need be.

Thanks to @squints for his post

function hide_review_form( $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', 'hide_review_form' );

2 Answers 2

0

You can't just do a simple If statement like this? ...

if ( count( $usercomment ) < 1 ) {
    comment_form();
};

I don't know why you would have to unset it.

1
  • Thanks for the quick reply! Sadly changing the snippet to this did not change anything Nov 13, 2019 at 20:41
0

Try below code which is return comment count of current user who posted comments on post. get_comment() have count parameter which returns only count of comment. in your code you are using $commentdata variable which is not defined. I have tested below code and it is working fine for me. let me know if this works for you.

global $current_user, $post;

if ( ! is_user_logged_in() ) {
    comment_form();
} else {

      $is_commented_count = get_comments(array('user_id' => $current_user->ID, 'post_id'=>$post->ID,'count' => true) );
      if($is_commented_count < 1) {
          comment_form();
      }
}
1
  • Thank you for posting this. Unfortunately it did not work for me. I'm getting close but still not quite there. (see updated answer) Nov 14, 2019 at 18:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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