Display Empty Star rating on tiled and product grid to balance the size of tiled
-
Dear woodmart,
Last I updated theme and empty star rating disapeared so again I want to display empty star rating with review (0) review number on all product tiled and product grid to balance the size of tiled.
Attachments:
You must be
logged in to view attached files.
Hello,
By default, if the product has no review no stars appear in the product grid.
Please make the full backup of your site and check the issue on the Storefront theme to detect if our theme causes the problem. Storefront is a free theme developed by WooСommerce.
Best Regards
`add_action(‘woocommerce_after_shop_loop_item_title’, ‘ehi_woocommerce_template_single_excerpt’, 5);
function ehi_woocommerce_template_single_excerpt() {
// The “echo ‘</a>’;” line below MAY BE needed to close the anchor tag (link/href) added for product images
// That way, we can use a different (custom) link for our star ratings and star rating text
// Comment this out if it is not applicable in your case.
echo ‘</a>’;
global $product;
$rating = $product->get_average_rating();
if ( $rating > 0 ) {
$title = sprintf(__( ‘Rated %s out of 5:’, ‘woocommerce’ ), $rating);
} else {
$title = ‘Rate this product:’;
$rating = 0;
}
$rating_html = ‘</a><a href=”‘ . get_the_permalink() . ‘#respond”><div class=”star-rating ehi-star-rating”><span style=”width:’ . (( $rating / 5 ) * 100) . ‘%”></span></div><span style=”font-size: 0.857em;”><em><strong>’ . $title . ‘</strong></em></span></a>’;
echo $rating_html;
// Now we display the product short description. This is optional.
wc_get_template(‘single-product/short-description.php’);
}
Hello,
Please make the full backup of your site and you can try this code, we have not tested it and do not guarantee it would be compatible.
If you have any questions please feel free to contact us.
Best Regards