Product Reviews dynamically

New Member
13 0 0

I am creating a portion of the page via javascript (thru a dataset) and as part of building the html for the element, I am adding the below code to get the review stars. The problem is because this javascript call is completed after the page is loaded and rendered, the review stars *sometimes* show up, sometimes it doesn't. I am wondering if there is a way to address that when you append new DOM elements to your html source dynamically. 

<div class="shopify-product-reviews-badge" data-id="{{ product.id }}"></div>

 

0 Likes
New Member
13 0 0

I tried loading the SPR js again but that didn't help, but got the below error. 

TypeError: SPR.$ is undefined

...eet(),SPR.loadjQuery(function(){return SPR.$.ajaxSetup({cache:!1}),SPR.loadjQuer...

Is there a way to force reload the product reviews? Any help is greatly appreciated

 

0 Likes
Highlighted
New Member
2 0 0

Put below script to refresh Shopify product review after your ajax call back:
SPR.registerCallbacks();
SPR.initRatingHandler();
SPR.initDomEls();
SPR.loadProducts();
SPR.loadBadges();

0 Likes