After changing all that things and fix the error on line 9 the code is not showing error now but not showing the stars also
add_action(‘woocommerce_after_shop_loop_item_title’, ‘njengah_woocommerce_template_single_excerpt’, 5);
function njengah_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’);
}