WooCommerce Review Author Hook on Review Submission

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.

Topic woocommerce-offtopic review Wordpress

Category Web


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:

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.