I want to hide the Yotpo reviews section whenever a product has no reviews. Can someone help me?

Duncan8
Visitor
3 0 0

Like it says in the title:

I have a client's site that uses Yotpo for reviews and such. It works fine, but we want to make it so it doesn't feature on any page where there aren't any reviews. Clients get review requests in their email and, so long as they've left at least one, it's fine to have the reviews section feature. But how do I hide it when there aren't any reviews on a product? Someone on Reddit recommended the following to me but it didn't work:

 

Basically just adding the following code to product.liquid

<script>$(document).ready(function(){if (!$(Yotpo.getStars()).find("span:not('.yotpo-icon-empty-star')").length) $(Yotpo.widgets.main.selector).hide();});</script>

Replies 2 (2)

NegativeSpace
Shopify Partner
18 3 6

The body of the code 

if (!$(Yotpo.getStars()).find("span:not('.yotpo-icon-empty-star')").length) $(Yotpo.widgets.main.selector).hide();

 should work. I believe the problem is that $(document).ready() is only waiting for the page to load, not the yotpo widget.

Try wrapping the above code in yotpo.onAllWidgetsReady(function() {}) like this 

yotpo.onAllWidgetsReady(function(){
  if (!$(Yotpo.getStars()).find("span:not('.yotpo-icon-empty-star')").length) 
    $(Yotpo.widgets.main.selector).hide();
})

I think it will work but I wasn't able to test it out

Let me know if it does

Will_Westwood
Tourist
5 0 2

Bit late, but there's a setting to turn this off!

It's called empty state in widget settings.

 

Screenshot_1.jpg