The source code of the files
I. snippets/a2reviews-widget.liquid
Main widget: Use to display a list of product reviews or feature reviews. This code can only be used to display a single product, or to display on the “Happy customer” page. You can also display the feature product on the homepage.
{% assign A2MetaProduct = product.metafields.a2reviews %}
<div class="container page-width a2reviews-container">
{% if type == 'QA' %}
{% if shop.metafields.a2reviews.qa_status != 0 %}
<a2-questions
lang="{{ shop.locale }}"
handle="{{ product.handle }}">
</a2-questions>
{% endif %}
{% else %}
<a2-reviews
handle="{{ product.handle }}"
lang="{{ shop.locale }}">
</a2-reviews>
{% endif %}
</div>
<div style="width:100%;height:40px;clear:both;"></div>
{% if template contains 'product' and type != 'QA' %}
{%- assign a2_current_variant = product.selected_or_first_available_variant -%}
{%- if cart.currency.iso_code == 'GBP' or cart.currency.iso_code == 'USD' or cart.currency.iso_code == 'AUD' or cart.currency.iso_code == 'AED' or cart.currency.iso_code == 'CAD' or cart.currency.iso_code == 'BWP' or cart.currency.iso_code == 'BND' or cart.currency.iso_code == 'DOP' or cart.currency.iso_code == 'GTQ' or cart.currency.iso_code == 'HKD' or cart.currency.iso_code == 'INR' or cart.currency.iso_code == 'ILS' or cart.currency.iso_code == 'YEN' or cart.currency.iso_code == 'KES' or cart.currency.iso_code == 'KOR' or cart.currency.iso_code == 'LBP' or cart.currency.iso_code == 'MYR' or cart.currency.iso_code == 'MXN' or cart.currency.iso_code == 'NPR' or cart.currency.iso_code == 'NZD' or cart.currency.iso_code == 'NIO' or cart.currency.iso_code == 'NGN' or cart.currency.iso_code == 'PKR' or cart.currency.iso_code == 'CNY' or cart.currency.iso_code == 'PHP' or cart.currency.iso_code == 'SGD' or cart.currency.iso_code == 'LKR' or cart.currency.iso_code == 'CHF' or cart.currency.iso_code == 'TWD' or cart.currency.iso_code == 'TSH' or cart.currency.iso_code == 'THB' or cart.currency.iso_code == 'UGX' or cart.currency.iso_code == 'KWD' or cart.currency.iso_code == 'CLP' -%}
{%- assign a2_product_price = a2_current_variant.price | money_without_currency | remove:',' -%}
{%- else -%}
{%- assign a2_product_price = a2_current_variant.price | money_without_currency | remove:'.' | replace: ',', '.' -%}
{%- endif -%}
<script type="application/ld+json">
{
"@context": "https://schema.org/",
"@type": "Product",
"brand": {
"@type": "Brand",
"name": "{{ product.vendor | escape }}"
},
"description": "{{ product.description | strip_html | truncatewords: 50 }}",
"sku": "{{ a2_current_variant.sku }}",
"mpn": "{{ a2_current_variant.barcode }}",
"image": "https:{{ product.featured_image.src | img_url: 'grande' }}",
"name": "{{ product.title }}",
"review": [{% for review in A2_Reviews limit:2 %}{
"@type": "Review",
"reviewRating": {
"@type": "Rating",
"ratingValue": "{{ review.rating }}"
},
"author": {
"@type": "Person",
"name": "{{ review.author }}"
},
"reviewBody": "{{ review.content }}"
}{% if forloop.last != true %},{% endif %}{% endfor %}],
{%- if A2MetaProduct.total_rating > 0 -%}
"aggregateRating": {
"@type": "AggregateRating",
"ratingValue": "{{ A2MetaProduct.avg_rating }}",
"bestRating": "5",
"ratingCount": "{{ A2MetaProduct.total_rating }}"
},
{% endif %}
"offers": {
"@type": "Offer",
"url": "{{ shop.url }}{{ a2_current_variant.url }}",
"priceCurrency": "{{ cart.currency.iso_code }}",
"price": "{{ a2_product_price }}",
"priceValidUntil": "{{ 'now' | date: '%s' | plus: 31536000 | date: '%Y-%m-%d' | uri_encode | replace:'+','%20' }}",
"itemCondition": "https://schema.org/UsedCondition",
"availability": "http://schema.org/{% if a2_current_variant.available %}InStock{% else %}OutOfStock{% endif %}",
"seller": {
"@type": "Organization",
"name": "Shopify"
}
}
}
</script>
{% endif %}
2. snippets/a2reviews-total.liquid
Total widget: This is a widget to display the total number of reviews for a product, it can be used on the product page or in a loop of products in a collection.
{% assign A2MetaSettings = shop.metafields.a2reviews.settings.value %}
{% assign A2MetaProduct = product.metafields.a2reviews %}
{% assign A2MetaCollection = collection.metafields.a2reviews %}
{% if A2MetaCollection.status == 0 and type == 'collection' %}
{% comment %} Hide on special collection {% endcomment %}
{% else %}
{% if A2MetaProduct.total_rating > 0 or A2MetaSettings.show_zero_count != false %}
<a2-reviews-total
{% if type == 'collection' %}collection{% endif %}
handle="{{ product.handle }}"
total="{% if A2MetaProduct.status == 0 %}0{% else %}{{ A2MetaProduct.total_rating }}{% endif %}"
avg="{% if A2MetaProduct.status == 0 %}0{% else %}{{ A2MetaProduct.avg_rating }}{% endif %}"
lang="{{ shop.locale }}"
{% if type != 'collection' %}is-scroll{% endif %}
>
</a2-reviews-total>
{% endif %}
{% endif %}
3. snippets/a2reviews-head-var.liquid
Global Configuration: This is the file that will contain the store's configuration content in the A2Reviews application. It's built to build a global variable for JavaScript.
{% comment %} This file automatically generated please do not change (v2). {% endcomment %}
{% assign a2IsTemporaryDisable = shop.metafields.a2reviews.isTemporaryDisable %}
{% assign a2_settings = shop.metafields.a2reviews.settings.value %}
<script type="text/javascript">var A2_Reviews_Shopify = { domain:"{{shop.domain}}", loading_url:"https://cdn.a2rev.com/icons/loading-orange.svg", settings:{{a2_settings | json}}, observer_active:true}</script>
{% if a2IsTemporaryDisable != 1 and a2_settings.loadInHead == true %}
{%- if a2_settings.script_options contains template -%}
{% comment %} No a2reviews script {% endcomment %}
{% else %}
<script type="text/javascript">document.addEventListener("DOMContentLoaded",()=>{(function(){d=document;s=d.createElement("script");s.src="https://s1-cdn.a2rev.com/a2/client-core/js/app.js?shop={{shop.domain}}×tamp=1647171073";s.async=1;d.getElementsByTagName("head")[0].appendChild(s);})();});</script>
{% endif %}
{% endif %}
4. sections/a2reviews-main-widget.liquid
Customize Block: This is a configuration file so you can drag and drop Section in Customize theme mode in Shopify admin. This block only appears on the product page.
{% render 'a2reviews-widget' product:product %}
{% schema %}
{
"name": "A2Reviews Main Widget",
"class": "a2reviews-section",
"settings": [],
"presets": [
{
"name": "A2Reviews Main Widget",
"category": "A2Reviews"
}
],
"templates": ["product"]
}
{% endschema %}
{% stylesheet %}
{% endstylesheet %}
{% javascript %}
{% endjavascript %}
5. sections/a2reviews-block.liquid
Customize Block: This is a configuration file so you can drag and drop Section in Customize theme mode in Shopify admin. This block is used on all pages. You need to create Block in A2Reviews app, then use ID to fill in the required field.
<div class="a2reviews-block-wrapper page-width">
<a2reviews-block block-id="{{ section.settings.block_id }}" name="{{ section.settings.block_name }}"></a2reviews-block>
</div>
{% schema %}
{
"name": "A2Reviews Block",
"class": "a2reviews-section",
"settings": [{
"type": "text",
"id": "block_id",
"label": "Block Id",
"default": "0",
"info": "Text",
"placeholder": "A2Reviews Block ID"
}, {
"type": "text",
"id": "block_name",
"label": "Block Name",
"default": "Reviews on homepage",
"info": "Text",
"placeholder": "A2Reviews Block Name"
}],
"presets": [
{
"name": "A2Reviews Block",
"category": "A2Reviews"
}
]
}
{% endschema %}
{% stylesheet %}
{% endstylesheet %}
{% javascript %}
{% endjavascript %}
Last updated