[Resolved] display rating – hide if none

Home Forums Support display rating – hide if none

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1154706
    maggew

    How do I “hide” rating if there is no review for a product on Catalog page? I still desire review rating be displayed for products that have a rating though… just hide the ones that do not.

    Customizing ▸ Layout ▸ WooCommerce ▸ Display Rating

    If working with a few dozen products, I think it looks bad when there are a bunch of empty stars.

    Might you know, if this was already asked? I searched but only briefly… didn’t look like like someone asked this already.

    Maybe, if it’s not hard either, could add a number of ratings after the stars to the product rating on catalog page.

    #1155107
    David
    Staff
    Customer Support

    Hi there,

    try this CSS:

    .woocommerce .products .star-rating[title~="Not"] {
        display: none;
    }
    #1155912
    maggew

    Nice share David!! Brilliant!

    🙂

    Thanks again!

    Might you know how to show # of reviews (excluding “customer review” text) next to the stars on catalog page? That would be a nice touch. I think.

    On the single product page, the HTML looks like:

    <a href="#reviews" class="woocommerce-review-link" rel="nofollow">(<span class="count">1</span> customer review)</a>

    #1155952
    David
    Staff
    Customer Support

    Do you have a link to a product with some reviews so i can take a look ?

    #1159113
    maggew

    Sadly, no, test environment is local. It’s just a standard WordPress site with 1 fake sample review. Let me see if I can find a woocommerce demo website… one second.

    Alright here we go! https://themes.woocommerce.com/storefront/product/flying-ninja/

    Notice how it say’s “(4 customer reviews)”? How do we loop (4) onto the store page for GP to show after star rating? So gpexample.dev/shop website has a test product with 1 review. Right now, it just has Product name and displays stars, but no (*) after the stars.

    Thanks again!

    #1159513
    David
    Staff
    Customer Support

    Try adding this PHP snippet to your site:

    add_filter( 'woocommerce_product_get_rating_html', function ( $html, $rating, $count ) {
    	global $product;
    	if ( $html && is_archive() && $product) {
    		$html .= sprintf( '<span class="review-count">(%s)</span>', $product->get_rating_count() );
    	}
    
    	return $html;
    }, 10, 3 );

    And this CSS to place them stars and count inline:

    .woocommerce ul.products li.product .star-rating {
        display: inline-block;
    }
Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.