Skip to content

Instantly share code, notes, and snippets.

@mborodov
Last active November 17, 2021 11:31
Show Gist options
  • Save mborodov/244bd76f2b8f95739c53afac412d15fe to your computer and use it in GitHub Desktop.
Save mborodov/244bd76f2b8f95739c53afac412d15fe to your computer and use it in GitHub Desktop.
Reviews counter for Shopify Product Reviews App (use: Reviews ({% include 'reviews-count' %}))
{%- 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 }}
@notrealdev
Copy link

Liquid makes things complicated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment