Home Forums WoodMart support forum Shop Page – How to keep the review stars always visible ? Reply To: Shop Page – How to keep the review stars always visible ?

#188955

rhg-designs
Participant

Strange…. this is the full code I inject with the plugin “My Custom Functions”. Hopefully this helps. See attachment.

add_action('woocommerce_after_shop_loop_item', 'add_star_rating' );
function add_star_rating()
{
global $woocommerce, $product;
$average = $product->get_average_rating();

echo '<div class="star-rating"><span style="width:'.( ( $average / 5 ) * 100 ) . '%"><strong itemprop="ratingValue" class="rating">'.$average.'</strong> '.__( 'out of 5', 'woocommerce' ).'</span></div></br>';
}
add_action( 'woocommerce_after_shop_loop_item_title', 'conditionally_remove_loop_rating', 4 );
function conditionally_remove_loop_rating(){
    global $product;

    if( ! ( $product->get_review_count() > 0 ) ) {
        remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_rating', 5 );
    }
}
Attachments:
You must be logged in to view attached files.