Show product rating on Woocommerce product page

Messy
5 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.
3 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
Administración web
62 Posts
Administración web posted this 08 June 2019

Hi Olivia, I'm needing exactly the same, How to add the qualification of the product but in the template "Products"? You mention that must be done in the CMS Code but I can not know what code I have to put...
Would you please help me by sharing this code with me?

Thank you very much.

Hi Olivia, I'm needing exactly the same, How to add the qualification of the product but in the template "Products"? You mention that must be done in the CMS Code but I can not know what code I have to put... Would you please help me by sharing this code with me? Thank you very much.
Support Team
Support Team posted this 10 June 2019

Hello,

As mentioned, in Woocommerce it is possible to add Product Rating on Product Details template only. For this please add the CMS Code control to any place on Product Details (Insert tab >> More >> CMS Code). Then click Edit Code and put the code provided above.

Sincerely,
Nettie

Hello, As mentioned, in Woocommerce it is possible to add Product Rating on Product Details template only. For this please add the CMS Code control to any place on Product Details (Insert tab >> More >> CMS Code). Then click Edit Code and put the code provided above. Sincerely, Nettie
You must log in or register to leave comments