admin管理员组文章数量:1406306
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 badges1 Answer
Reset to default 0If 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.
本文标签: woocommerce offtopicUse Hooks to Limit One Comment Per User Per PostHide Form if Already Commented
版权声明:本文标题:woocommerce offtopic - Use Hooks to Limit One Comment Per User Per Post - Hide Form if Already Commented 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745006199a2637278.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论