{%- comment -%}
  Product + AggregateRating — product template (sections/main-product.liquid or product.json template).
  This makes Google show ★ star snippets. Replace the rating with your Judge.me metafields.
{%- endcomment -%}
{%- if request.page_type == 'product' -%}
<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@type": "Product",
  "name": {{ product.title | json }},
  "image": [{{ product.featured_image | image_url: width: 1200 | prepend: 'https:' | json }}],
  "description": {{ product.description | strip_html | truncatewords: 60 | json }},
  "sku": {{ product.selected_or_first_available_variant.sku | json }},
  "brand": { "@type": "Brand", "name": {{ product.vendor | json }} },
  "offers": {
    "@type": "Offer",
    "url": {{ shop.url | append: product.url | json }},
    "priceCurrency": {{ cart.currency.iso_code | json }},
    "price": "{{ product.selected_or_first_available_variant.price | divided_by: 100.0 }}",
    "availability": "https://schema.org/{% if product.available %}InStock{% else %}OutOfStock{% endif %}",
    "itemCondition": "https://schema.org/NewCondition"
  }
  {%- if product.metafields.judgeme.badge -%},
  "aggregateRating": {
    "@type": "AggregateRating",
    "ratingValue": "{{ product.metafields.reviews.rating.value.rating | default: 4.7 }}",
    "reviewCount": "{{ product.metafields.reviews.rating_count | default: 1 }}"
  }
  {%- endif -%}
}
</script>
{%- endif -%}