Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

186
Views
Custom JS variable for GTM

This i need to return for product page

And this i have to return for listing pages, trough loop

    function() {
  var prodRate=document.querySelector('div.summary.entry-summary > div.woocommerce-product-rating > p').innerText.replace('Product Rate:','');
  var rating = document.querySelectorAll('.star-rating');
  var starRating =[];
  for(i=0;i<rating.length;i++){
  starRating.push(rating[i].innerText)};
  
  var averageRating = starRating || prodRate;  

 return averageRating;
}

I have to return one of the values that is displayed as product rating. On listing page this rating is displayed as "aria-label", and on product page as the value of p. How can i set a one single variable, that returns the needed value of product rating. I am traying above mentioned function, but it doesn't work properly. Thank you a lot and sorry for such newbie question.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!