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

Duncan8
New Member
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>

0 Likes
NegativeSpace
Excursionist
11 2 4

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

0 Likes