woocommerce offtopic - Use Hooks to Limit One Comment Per User Per Post - Hide Form if Already Commented

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

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?

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?

Share Improve this question edited Apr 13, 2017 at 12:37 CommunityBot 1 asked Nov 18, 2016 at 16:59 squintssquints 112 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745006200a4605797.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信