Skip to content

Instantly share code, notes, and snippets.

@amdrew
Last active January 3, 2016 10:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amdrew/8447714 to your computer and use it in GitHub Desktop.
Save amdrew/8447714 to your computer and use it in GitHub Desktop.
Call this function on the single product page with <?php echo sumobi_custom_show_average_star_rating(); ?>
<?php
function sumobi_custom_show_average_star_rating() {
// make sure edd reviews is active
if ( ! function_exists( 'edd_reviews' ) )
return;
$edd_reviews = edd_reviews();
// get the average rating for this download
$average_rating = (int) $edd_reviews->average_rating( false );
$rating = $average_rating;
ob_start();
?>
<div itemprop="reviewRating" itemscope itemtype="http://schema.org/Rating" class="star-rating">
<div class="edd_reviews_rating_box" role="img" aria-label="<?php echo $rating . ' ' . __( 'stars', 'edd-reviews' ); ?>">
<div class="edd_star_rating" style="width: <?php echo ( 19 * $rating ); ?>px"></div>
</div>
<div style="display:none" itemprop="reviewRating" itemscope itemtype="http://schema.org/Rating">
<meta itemprop="worstRating" content="1" />
<span itemprop="ratingValue"><?php echo $rating; ?></span>
<span itemprop="bestRating">5</span>
</div>
</div>
<?php
$rating_html = ob_get_clean();
return $rating_html;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment