How to Remove Ratings from Woocommerce Replies by Administrators, and Make Other Customizations to Reviews

You’re running a Woocommerce store and someone left a review, yay!

Now, you want to respond to the review in WordPress to say thanks or otherwise address the review.

screenshot of a fake comment and response in the WordPress backend editor
WordPress’ backend comment editor.

The problem is, if you respond like this, Woocommerce will want to display the reply as a review, too, which means you’ll show an empty star rating and even worse, Google will fail the page for Rich Snippets.

screenshot of the same comments as above, on the front end now
One possible way to display comments on a front end Woocommerce / WordPress theme.
screenshot showing how this will make a rich snippet fail in Google's tests
Failed!

The Code

Basically, we want to be able to modify our custom Woocommerce theme and how it exports this information. To do this, we can check whether the comment is an original (in which the user would have been forced to choose a star rating) or a reply (which an admin would have made in Woocommerce):

<?php $comment_type = 'store-reply';
if ('0' == $comment->comment_parent) {
$comment_type = 'customer-review';
}

Basically, this says “If the comment doesn’t have a parent, it’s not a reply.”

From there, we can then do things like this:

<?php if ($comment_type == 'customer-review') { ?><span itemprop="reviewRating" itemscope itemtype="http://schema.org/Rating">
<span itemprop="ratingValue"><?php echo $rating; ?></strong> <?php _e( 'out of 5', 'woocommerce' ); ?></span><?php } ?></span>

Don’t copy / paste that code, it will only work if you have already defined $rating, it’s just an example of how this all works.

Now you can pick and choose which portions of your template you show when the review is an actual review versus a response from a store administrator!

Up Next: Making Dropdowns Work on Touch Devices like Tablets