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