Enhanced Schema.org Markup for Shopify Products with Additional Review Properties, Product-Specific

dealnest
Tourist
21 0 3

How can I improve the Schema.org markup for my Shopify products to include additional review properties, product-specific variables, and aggregate review data?

 

 

{% if product.reviews.size > 0 %}
  {% assign ratingCount = product.reviews.size %}
  {% assign ratingValue = 0 %}
  {% for review in product.reviews %}
    {% assign ratingValue = ratingValue | plus: review.rating %}
  {% endfor %}
  {% assign averageRating = ratingValue | divided_by: ratingCount %}
  {% assign bestRating = 5 %}
  {% assign worstRating = 1 %}
  
  <script type="application/ld+json">
  {
    "@context": "https://schema.org/",
    "@type": "Product",
    "name": "{{ product.title }}",
    "image": "{{ product.featured_image.src | img_url: 'large' }}",
    "description": "{{ product.description | strip_html | escape }}",
    "sku": "{{ product.sku }}",
    "mpn": "{{ product.metafields.global.manufacturer_part_number }}",
    "brand": {
      "@type": "Brand",
      "name": "{{ product.vendor }}"
    },
    "offers": {
      "@type": "Offer",
      "price": "{{ product.price | money_without_currency }}",
      "priceCurrency": "{{ shop.currency }}",
      "availability": "{% if product.available %}https://schema.org/InStock{% else %}https://schema.org/OutOfStock{% endif %}",
      "seller": {
        "@type": "Organization",
        "name": "{{ shop.name }}"
      }
    },
    "aggregateRating": {
      "@type": "AggregateRating",
      "ratingValue": "{{ averageRating }}",
      "reviewCount": "{{ ratingCount }}",
      "bestRating": "{{ bestRating }}",
      "worstRating": "{{ worstRating }}"
    },
    "review": [
      {% for review in product.reviews %}
        {
          "@type": "Review",
          "author": {
            "@type": "Person",
            "name": "{{ review.author }}"
          },
          "datePublished": "{{ review.created_at | date: "%Y-%m-%d" }}",
          "description": "{{ review.body | strip_html | escape }}",
          "reviewRating": {
            "@type": "Rating",
            "ratingValue": "{{ review.rating }}",
            "bestRating": "{{ bestRating }}",
            "worstRating": "{{ worstRating }}"
          }
          {% if forloop.last == false %},{% endif %}
        }
      {% endfor %}
    ]
  }
  </script>
{% endif %}

 

 

 

Replies 0 (0)