Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello

    Please remember if the product have not been voted, there is not reason to show any stars. The stars only appears when a product have been voted.

    Thanks.

    BladimirJavier if you don’t have the answer, don’t reply with an unhelpful answer. Everyone has a different use case, some people want the stars to show to keep the layout and design consistent.

    As for the OPs question. If you have Woocommerce setup correctly with a ‘woocommerce’ folder in the root of your theme, you can simply go into woocommerce>loop>rating.php

    In the rating.php file, where you see:

    <?php if ( $rating_html = $product->get_rating_html() ) : ?>
    	<?php echo $rating_html; ?>
    <?php endif; ?>

    Replace it with:

    <?php if ( $rating_html = $product->get_rating_html() ) { ?>
    	<?php echo $rating_html; ?>
    <?php } else {
    $rating_html  = '<div class="star-rating" title="' . sprintf( __( 'Rated %s out of 5', 'woocommerce' ), $rating ) . '">';
      $rating_html .= '<span style="width:' . ( ( $rating / 5 ) * 100 ) . '%"><strong class="rating">' . $rating . '</strong> ' . __( 'out of 5', 'woocommerce' ) . '</span>';
      $rating_html .= '</div>';
      echo $rating_html;
    }?>

    thanks for the above code as it pointed me in the right direction but the above code did not work for me so i just added this instead,

    <?php if ( $rating_html = $product->get_rating_html() ) { ?>
    	<?php echo $rating_html; ?>
    <?php } else {
    echo '<div class="star-rating" title="Rated 5.00 out of 5"></div>' ;
    }?>
Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Empty stars with Woocommerce’ is closed to new replies.