var data; fetch("https://api.reviews.io/stats/all?store=sturcookware.de") .then(response => response.json()) .then(data => { var product_average_rating = data.product_review_stats.average_rating; var product_total_reviews = data.product_review_stats.total_reviews; var company_average_rating = data.company_review_stats.average_rating; var company_total_reviews = data.company_review_stats.total_reviews; var third_party_average_rating = data.third_party_review_stats.average_rating; var third_party_total_reviews = data.third_party_review_stats.total_reviews; var totalReviews =(product_total_reviews+company_total_reviews+third_party_total_reviews); var totalAverage = ((product_average_rating*product_total_reviews+company_average_rating*company_total_reviews+third_party_average_rating*third_party_total_reviews)/totalReviews); var totalAverageRounded = Math.round(totalAverage * 100) / 100; var totalAverageFormatted = totalAverageRounded.toLocaleString("de-DE"); var totalReviewsFormatted = totalReviews.toLocaleString("de-DE"); var OnelineRatingNodes = document.querySelectorAll(".reviews-score"); OnelineRatingNodes.forEach(function (currentValue, currentIndex, listObj) { currentValue.innerText = totalAverageFormatted; }); var OnelineRatingCountNodes = document.querySelectorAll(".reviews-count"); OnelineRatingCountNodes.forEach(function (currentValue, currentIndex, listObj) { currentValue.innerText = totalReviewsFormatted; }); setDynamicReviewCount(totalReviewsFormatted); setTimeout(() => { setDynamicReviewCount(totalReviewsFormatted); }, "1000"); }) function setDynamicReviewCount(totalReviewsFormatted) { document.querySelectorAll(".shopify-section--reviews-carousel").forEach(function (section) { let ReviewsCountElem = section.querySelector(".h2 em"); if(ReviewsCountElem){ ReviewsCountElem.innerHTML = totalReviewsFormatted; setTimeout(() => { const reviewsIOTotalReviews = document.querySelector(".shopify-section--reviews-carousel .CarouselWidget__header .header__inner > .R-TextBody:nth-child(4) .cssVar-subheading__number").innerHTML; if (reviewsIOTotalReviews && reviewsIOTotalReviews != totalReviewsFormatted) { ReviewsCountElem.innerHTML = reviewsIOTotalReviews; } }, "2000"); } }); }