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' );
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' );
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.
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();
}
}