Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephenkeable/db757259de19b18aaf82fb9cf032ed26 to your computer and use it in GitHub Desktop.
Save stephenkeable/db757259de19b18aaf82fb9cf032ed26 to your computer and use it in GitHub Desktop.
{%- assign tag_alt = "BLANK" -%}
{%- for tag in product.tags -%}
{%- assign tag_prefix = tag | slice: 0, 5 -%}
{%- if tag_prefix == "_alt_" -%}
{%- assign tag_alt = tag -%}
<!-- looking for tag {{ tag_alt }} -->
{%- break -%}
{%- else -%}
<!-- tag {{ tag }} has no "_alt" prefix -->
{%- endif -%}
{%- else -%}
<!-- no product tags found -->
{%- endfor -%}
{%- unless tag_alt == "BLANK" -%}
{%- assign vendor_handle = product.vendor | handle -%}
<!-- looking for collection /collections/{{vendor_handle}} -->
{%- if collections[vendor_handle].products.size > 0 -%}
{%- assign alt_products_total = 0 -%}
{%- capture products_output -%}
{%- paginate collections[vendor_handle].products by 200 -%}
{%- for alt_product in collections[vendor_handle].products -%}
{%- if alt_product.tags contains tag_alt -%}
{%- unless alt_product.id == product.id -%}
{%- assign alt_products_total = alt_products_total | plus: 1 -%}
<a href="{{ alt_product.url }}" title="{{ alt_product.title }}"><img src="{{ alt_product.featured_image | img_url: '90x90', crop: 'center', format: 'pjpg' }}" alt="{{ alt_product.title }}"></a>
{%- else -%}
<!-- product {{ alt_product.title }} is the current product so we skip -->
{%- endunless -%}
{%- else -%}
<!-- product {{ alt_product.title }} doesn't have the {{ tag_alt }} tag -->
{%- endif -%}
{%- else -%}
<!-- no products in the {{ vendor_handle }} collection -->
{%- endfor -%}
{%- endpaginate -%}
{%- endcapture -%}
{%- else -%}
<!-- {{ vendor_handle }} collection has no products or doesn't exist -->
{%- endif -%}
{%- else -%}
<!-- no tag_alt set -->
{%- endunless -%}
{%- if alt_products_total > 0 -%}
<br><br>
<p><strong>Also Available In:</strong></p>
<div class="product-alt-colours">
{{ products_output }}
</div>
{%- else -%}
<!-- 0 products found -->
{%- endif -%}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment