Support » Plugin: WooCommerce » Rounding up star rating

  • In our Woocommerce store we have a lot of positive product reviews. For one of our products the average rating is 4.98 out of 5.

    The displayed star rating however rounds this down to a star rating of 4.5 filled stars.

    To me this seems to be a rounding error. Would it be possible to display the rating average based on the closest half star? For example: 4.9 would be 5 stars, 4.6 would be 4.5 stars, 4.18 would be 4 stars – and so on.

Viewing 1 replies (of 1 total)
  • The responsible code seems to be in title.php. But my php skills aren’t sufficient to solve the problem yet.

    <?php
    /**
     * Single Product title
     *
     * @author 		WooThemes
     * @package 	WooCommerce/Templates
     * @version     1.6.4
     */
    
    global $product, $show_rating_below_title, $is_quickview;
    
    if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
    
    $stars = '';
    
    if( ! $product)
    	return;
    
    if($show_rating_below_title)
    {
    	$count   = $product->get_rating_count();
    	$average = $product->get_average_rating();
    
    	if($count)
    	{
    		$stars = "<div class=\"rating rating-inline filled-" . absint($average) . ($average - intval($average) > .49 ? ' and-half' : '') . "\" itemprop=\"aggregateRating\" itemscope itemtype=\"http://schema.org/AggregateRating\" title=\"" . sprintf( __( 'Rated %s out of 5', 'woocommerce' ), $average ) . "\">
    
    		<span class=\"glyphicon glyphicon-star star-1\"></span>
    		<span class=\"glyphicon glyphicon-star star-2\"></span>
    		<span class=\"glyphicon glyphicon-star star-3\"></span>
    		<span class=\"glyphicon glyphicon-star star-4\"></span>
    		<span class=\"glyphicon glyphicon-star star-5\"></span>
    
    	</div>";
    	}
    }
    ?>
    
    <h1 itemprop="name" class="product_title entry-title"><?php the_title(); ?></h1>
    
    <?php if(get_data('shop_single_product_category')): ?>
    
    	<?php echo wc_get_product_category_list( $product->get_id(), ', ', '<span class="posted_in">', $stars . '</span>' ); ?>
    
    <?php else: ?>
    
    	<br />
    
    <?php endif; ?>
Viewing 1 replies (of 1 total)
  • The topic ‘Rounding up star rating’ is closed to new replies.