All things Shopify and commerce
{% if product.reviews.size > 0 %}
{% assign review = product.reviews.first %}
{% assign author = review.author %}
{% assign datePublished = review.created_at | date: "%Y-%m-%d" %}
{% assign reviewRatingValue = review.rating %}
{% 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 }}"
}
},
"review": {
"@type": "Review",
"author": {
"@type": "Person",
"name": "{{ author }}"
},
"datePublished": "{{ datePublished }}",
"description": "{{ review.body | strip_html | escape }}",
"reviewRating": {
"@type": "Rating",
"ratingValue": "{{ reviewRatingValue }}",
"bestRating": "{{ bestRating }}",
"worstRating": "{{ worstRating }}"
}
}
}
</script>
{% endif %}
Here's an improved Liquid code snippet for generating product schema markup with reviews:
{% assign product = product %}
{% assign product_url = shop.url | append: '/products/' | append: product.handle %}
{% assign product_price = product.price | times: 100 %}
{% assign product_image_url = product.featured_image.src | img_url: 'large' %}
{% assign product_rating_value = product.metafields.yotpo_overall_score or '' %}
{% assign product_rating_count = product.metafields.yotpo_total_reviews or '' %}
{% assign product_description = product.description | strip_html | truncate: 100 %}
<script type="application/ld+json">
{
"@context": "http://schema.org/",
"@type": "Product",
"name": "{{ product.title }}",
"image": "{{ product_image_url }}",
"description": "{{ product_description }}",
"brand": "{{ product.vendor }}",
"sku": "{{ product.sku }}",
"offers": {
"@type": "Offer",
"priceCurrency": "{{ shop.currency }}",
"price": "{{ product_price }}",
"availability": "{% if product.available %}InStock{% else %}OutOfStock{% endif %}"
},
"aggregateRating": {
"@type": "AggregateRating",
"ratingValue": "{{ product_rating_value }}",
"reviewCount": "{{ product_rating_count }}"
},
"review": [
{% for review in product.metafields.yotpo_reviews %}
{
"@type": "Review",
"reviewRating": {
"@type": "Rating",
"ratingValue": "{{ review.score }}"
},
"author": {
"@type": "Person",
"name": "{{ review.user_display_name }}"
},
"datePublished": "{{ review.date }}",
"description": "{{ review.content }}",
"name": "{{ review.title }}"
}{% unless forloop.last %},{% endunless %}
{% endfor %}
],
"url": "{{ product_url }}"
}
</script>
This code snippet includes:
Note: This code snippet assumes that your store is using Yotpo for product reviews. If you're using a different review app, you'll need to adjust the code accordingly.
i am using trust pilot app for reviews and ratings.can you please edit the code for trustpilot app so i can use in ny store.and help will be really appreciated.
User | RANK |
---|---|
42 | |
42 | |
32 | |
24 | |
20 |
Make the shift from discounts to donations, and witness your business not only thrive fina...
By Holly Dec 4, 2023On our Shopify Expert Marketplace, you can find many trusted third party developers and fr...
By Arno Nov 27, 2023You've downloaded the Search & Discovery app from the Shopify App store, and as you're ...
By Skye Nov 8, 2023