M
M
Maxim Demidov2018-11-02 15:18:18
WordPress
Maxim Demidov, 2018-11-02 15:18:18

How to display the number of reviews next to the rating stars?

Dear colleagues! There was a question on Woocommerce, tell me please, otherwise I broke my whole head. There is an online store on Woocommerce with a standard rating system (stars). How to display the number of reviews next to these asterisks? For example, under the product 5 stars, in brackets - 5 (i.e. the number of reviews left for this product). How can this be implemented?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex Vasilyev, 2018-11-08
@MaximusDem

There is a woocommerce template for displaying stars on the product page. You can search in the theme woocommerce/single-product/rating.php if your theme doesn't have it copy it from wp-content/plugin/woocommerce/template/single-product/rating.php.
And already there is a $review_count variable, use it.
Here is an example.

<?php

global $product;

if ( 'no' === get_option( 'woocommerce_enable_review_rating' ) ) {
  return;
}

$rating_count = $product->get_rating_count();
$review_count = $product->get_review_count();
$average      = $product->get_average_rating();

if ( $rating_count > 0 ) : ?>

  <div class="woocommerce-product-rating">
    <?php echo wc_get_rating_html( $average, $rating_count ); ?>
    <?php echo '(' . $review_count . ')'; ?> <!-- Количество отзывов -->
  </div>

<?php endif; ?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question