Last active
November 17, 2021 11:31
-
-
Save mborodov/244bd76f2b8f95739c53afac412d15fe to your computer and use it in GitHub Desktop.
Reviews counter for Shopify Product Reviews App (use: Reviews ({% include 'reviews-count' %}))
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{%- assign product_reviews_count=0 -%} | |
{%- if product.metafields.spr.reviews -%} | |
{%- capture review_data -%}{{ product.metafields.spr.reviews }}{%- endcapture -%} | |
{%- if review_data contains '"votes"' -%} | |
{%- assign keyword = '"votes"' -%} | |
{%- else -%} | |
{%- assign keyword = '"reviewCount"' -%} | |
{%- endif -%} | |
{%- assign rd_a1 = review_data | split: keyword -%} | |
{%- assign rd_a2 = rd_a1[1] | split: "=" -%} | |
{%- assign rd_a3 = rd_a2[1] | split: '"' -%} | |
{%- assign product_reviews_count = rd_a3[1] | plus: 1 | minus: 1 -%} | |
{%- endif -%} | |
{{ product_reviews_count }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Liquid makes things complicated