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 jimmijazz/9f38b640965e26988614cfb493936a18 to your computer and use it in GitHub Desktop.
Save jimmijazz/9f38b640965e26988614cfb493936a18 to your computer and use it in GitHub Desktop.
Product Bundling using tags and liquid
{% comment %}
=======================
PROUCT BUNDLING EXAMPLE
=======================
Adding in bundles based on tags
This section gets the product tags, looks for those with outfit:x where x == the product handle. -->
Then concatenates them all into one string.
{% endcomment %}
{% assign bundle = false %}
{% assign bundle_handles = "" %} <!-- Stores the handles if they exist -->
{% capture bundle_handles %}
{% for t in product.tags %}
{% if t contains "outfit" %}
{% assign bundle = true %}
{% assign bundle_product_array = t | split: ":" %}
{% assign bundle_product_handle = bundle_product_array.last %}
{{ bundle_product_handle }}
{% unless forloop.last %}:{% endunless %}
{% endif %}
{% endfor %}
{% endcapture %}
{% comment %}Here we actually display the product bundles if they exist {% endcomment %}
{% if bundle == true %}
<hr>
<h3>Shop the look </h3>
<!--Get the individual products -->
{% assign product_handles = bundle_handles | split: ":" %}
{% for p in product_handles %}
{% assign thehandle = p | strip %}
{% assign product = all_products[thehandle] %}
<p>Product Title : {{ product.title }} </p>
{% if product.available %}
<p><strong>Product Price :</strong> {{ product.price }} </p>
<p><strong>Product ID :</strong> {{ product.id }} </p>
{% else %}
<p>This product is not available </p>
{% endif %}
{% endfor %}
{% else %}
<!-- Normal product -->
{% endif %}
{% comment %}
=============================
End the product bundle snippet
=============================
{% endcomment %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment