Show product rating on Woocommerce product page

Messy
3 Posts
Messy posted this 16 January 2018

I can show the product rating on the Product detail page, but I want to show the rating on the Products page as well. Is this possible? I cannot see the option under Add control on the Products page. The option does exists on the Products Detail page.

I can show the product rating on the Product detail page, but I want to show the rating on the Products page as well. Is this possible? I cannot see the option under Add control on the Products page. The option does exists on the Products Detail page.
Vote to pay developers attention to this features or issue.
1 Comments
Order By: Standard | Newest
Support Team
Support Team posted this 17 January 2018

Hi,

Unfortunately Product Rating is not supported on the Products template.
The code which outputs the product rating on the Product Details is the following:

        <?php

if (get_option('woocommerce_enable_review_rating' ) !== 'no') {

    global $product;

    $rating_count = method_exists($product, 'get_rating_count')   ? $product->get_rating_count()   : 1;
    $review_count = method_exists($product, 'get_review_count')   ? $product->get_review_count()   : 1;
    $average      = method_exists($product, 'get_average_rating') ? $product->get_average_rating() : 0;

    if ($rating_count > 0) {
?>

<div class=" bd-productrating-1" itemprop="aggregateRating" itemscope itemtype="http://schema.org/AggregateRating">

    <div class=" bd-rating-2" title="<?php printf( __( 'Rated %s out of 5', 'woocommerce' ), $average ); ?>">
        <?php for ($i = 1; $i <= 5; $i++): ?>
            <span class="  bd-icon bd-icon-2 <?php if ($i <= round($average)) echo ' active'; ?>"></span>
        <?php endfor; ?>

        <span itemprop="ratingValue" style="display:none"><?php echo esc_html($average); ?></span>
        <span itemprop="ratingCount" style="display:none"><?php echo $rating_count; ?></span>
        <span itemprop="reviewCount" style="display:none"><?php echo $review_count; ?></span>
    </div>
</div>

<?php
    }
}
?>

It works on the Products template inside CMS CODE control too (Insert tab >> More). The only thing is classes like bd-productrating-1 or bd-rating-2 etc. They are different in different themes. You need to use the same classes as used on the Product Details template.

Thank you,
Olivia

Hi, Unfortunately Product Rating is not supported on the Products template. The code which outputs the product rating on the Product Details is the following: <?php if (get_option('woocommerce_enable_review_rating' ) !== 'no') { global $product; $rating_count = method_exists($product, 'get_rating_count') ? $product->get_rating_count() : 1; $review_count = method_exists($product, 'get_review_count') ? $product->get_review_count() : 1; $average = method_exists($product, 'get_average_rating') ? $product->get_average_rating() : 0; if ($rating_count > 0) { ?> <div class=" bd-productrating-1" itemprop="aggregateRating" itemscope itemtype="http://schema.org/AggregateRating"> <div class=" bd-rating-2" title="<?php printf( __( 'Rated %s out of 5', 'woocommerce' ), $average ); ?>"> <?php for ($i = 1; $i <= 5; $i++): ?> <span class=" bd-icon bd-icon-2 <?php if ($i <= round($average)) echo ' active'; ?>"></span> <?php endfor; ?> <span itemprop="ratingValue" style="display:none"><?php echo esc_html($average); ?></span> <span itemprop="ratingCount" style="display:none"><?php echo $rating_count; ?></span> <span itemprop="reviewCount" style="display:none"><?php echo $review_count; ?></span> </div> </div> <?php } } ?> It works on the Products template inside CMS CODE control too (Insert tab >> More). The only thing is classes like `bd-productrating-1` or `bd-rating-2` etc. They are different in different themes. You need to use the same classes as used on the Product Details template. Thank you, Olivia
You must log in or register to leave comments