In WooCommerce, product reviews are an effective way to build trust and encourage future purchases. In order to avoid spam, we usually turn on the "Only "Verified Users" can participate in reviews" option, which puts some limitations on the buyers who need to post a review, for example, if a user who has already purchased a product is not logged in, they can't post a review of the product.
In this tutorial, I'll show you how to customize WooCommerce to allow product reviews from buyers who are not logged in.
Step 1: Disable the "Only "verified users" can participate in the evaluation" option
By disabling this setting, we allow users toYou can submit product reviews even if you are logged out(So anyone can post a comment, including spambots):
This is just the first step, now we need some custom code to make sure we "validate" each product review, in the code below we verify that the user posting the review is the buyer who has purchased the product by checking the review's email.
Step 2: Block product reviews from non-WooCommerce customers using PHP code
add_filter( 'preprocess_comment', 'wprs_product_review_logged_out_only_verified' );
function wprs_product_review_logged_out_only_verified( $comment ) {
if ( 'product' === get_post_type( $comment['comment_post_ID'] ) ) {
if ( $comment['comment_author_email'] && ! $comment['user_id'] && ! wc_customer_bought_product( $comment['comment_author_email'], '', $comment['comment_post_ID'] ) ) {
wp_die( 'Sorry, you have not purchased this product, only users who have purchased the product can post a review.' ).
}
}
return $comment.
}
Audit form for logged out users + error message
After completing steps 1 and 2, you will see the following form in the "Reviews" tab of the individual product page in WooCommerce:
The only difference is that if you post a review using an email that you haven't purchased the product from, after submitting it, you will be redirected to an error message page.
Now "verified customers" can post a review without logging in, soYour "Product Review Submission" Conversion Rate May Go Up!!