Print WordPress API Call on Page/Post
In your template/post, add the following for the javascript to populate with the scores:
<span id="reviews">Loading reviews ...</span>
Then, you can use the following javascript to load the scores into that tag:
const url = "https://api.yotpo.com/products/Q6IzQniPhEwgOfDx2C58uKPy5G2OgNnZtPpQpfWI/4379928772/bottomline";fetch(url) .then(res => res.json()) .then(json => { const data = json.response; const avg = data.bottomline["average_score"]; const numReviews = data.bottomline["total_reviews"]; const textContent = `This is based on ${numReviews} with an average score of ${avg}`; document.getElementById('reviews').innerHTML = textContent; }) .catch(err => { alert("The reviews could not be loaded!"); console.error(err.message); });
Js fiddle Example: https://jsfiddle.net/s2zamerk/