0

By default posting a review in WooCommerce Product will add 'comment' record to Database with poster as author name. I'd like to hook Review Author Name because some customers don't want to login and leave a review, so an Admin will do for them. It's okay if the comment's user ID belongs to Admin, but what I want is the author name could be modified.

I know a review can be edited by some plugins, but would be great if we can add Author Name on Review form (if Admin) and tweak it on Review submission.

Any idea how to do this? Thanks in advance.

0

Found it!

Go to wp-includes > comment-templates.php.

Edit around line 2560:

else ( ! is_user_logged_in() ) {

to

else {

Then in my plugin .php file or your Theme 'function.php', add:

function modify_author($commentdata) {
  $commentdata['comment_author'] = $_POST['author']; // You should sanitize this.

  return $commentdata;
}
add_filter('preprocess_comment', 'modify_author');

I know it's bad idea to modify comment-templates.php, but it's working for me for now. Any ideas to show Guest Review Form through our own plugin would be appreciated. Thank you.

References:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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