Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Change reviews text on woocommerce product page WordPress

  • SOLVED

Hello I am looking to modify my woocommerce product page. I would like to change the way the reviews are displayed instead of "3 reviews" it will say "100% customers satisfied"

I have attached picture for example. I would like to add this as a function and not change any template.

Answers (1)

2019-11-13

Alex Miller answers:

Unfortunately, the code for this is baked into the WooCommerce template. You'll need to do a WooCommerce Template Override to achieve this:

https://docs.woocommerce.com/document/template-structure/#section-1

You want to copy the `woocommerce/templates/single/rating.php` template into your own themes `woocommerce` folder. You can then replace the conditional in that template with what I have below:

if ( $rating_count > 0 ) : ?>

<div class="woocommerce-product-rating">
<?php echo wc_get_rating_html( $average, $rating_count ); // WPCS: XSS ok. ?>
<?php if ( comments_open() ) : ?>
<?php //phpcs:disable ?>
<a href="#reviews" class="woocommerce-review-link" rel="nofollow">(<?php printf( esc_html__( '%s customers satisified' ), ( ( $average / 5 ) * 100 ) . '%' ); ?>)</a>
<?php // phpcs:enable ?>
<?php endif ?>
</div>

<?php endif; ?>


The important part is replacing the string in the template:

<a href="#reviews" class="woocommerce-review-link" rel="nofollow">(<?php printf( esc_html__( '%s customers satisified' ), ( ( $average / 5 ) * 100 ) . '%' ); ?>)</a>