Skip to content

Instantly share code, notes, and snippets.

@kyleaparker
kyleaparker / gist:9691004
Created March 21, 2014 17:12
Shopify: Show number of colors available
{% for option in product.options %}
{% if option contains "Color" %}
{% assign optionName = "option" | append: forloop.index %}
{% assign colors = product.variants | map: optionName %}
{% assign colorsFiltered = '' %}
{% for colorOption in colors %}
{% unless colorsFiltered contains colorOption %}
{% assign colorsFiltered = colorsFiltered | append: ', ' | append: colorOption %}
{% endunless %}
{% endfor %}
@kyleaparker
kyleaparker / gist:9665660
Created March 20, 2014 14:57
Shopify: Show number of variants still available
{% assign total = product.variants | map: 'available' | join: ", " | remove: 'false, ' %}
{% assign available = total | split: ',' %}
{{ available.size }} of {{ product.variants.size }} left
@kyleaparker
kyleaparker / gist:9665395
Created March 20, 2014 14:45
Shopify: Remove sold out options from variant drop down
{% if product.options.size == 1 %}
{% for variant in product.variants %}
{% unless variant.available %}
jQuery('.single-option-selector option:contains(' + {{ variant.title | json }} +')').remove();
{% endunless %}
{% endfor %}
jQuery('.single-option-selector').trigger('change');
{% endif %}
@kyleaparker
kyleaparker / gist:6c956128048bd1a69821
Created September 23, 2014 14:49
[Shopify] Three level collection navigation using tags
<ul>
{% comment %}A linklist should be created called "Collections" containing each of the "top" level collections{% endcomment %}
{% for link in linklists.collections.links %}
{% assign col = link.object %}
<li class="{% if col.handle == collection.handle %}active{% endif %}">
<a href="{{ link.url }}"><span>{{ link.title }}</span></a>
{% if col.all_tags.size > 0 %}
<ul>
{% assign tag_index = 0 %}
{% assign current_tag = "" %}
@kyleaparker
kyleaparker / gist:8851659
Created February 6, 2014 20:09
Shopify: Map all collection tags (avoid 50 product limit)
{% assign collection_tags = collection | map: 'tags' %}
{% for tag in collection_tags %}
<a href="/collections/{% if collection.handle != blank %}{{ collection.handle }}{% else %}all{% endif %}/{{ tag | handleize }}" title="{{ tag | escape }}">{{ tag }}</a>
{% endfor %}
@kyleaparker
kyleaparker / gist:7812970
Last active August 6, 2016 23:33
Shopify Lockdown App: How to remove the "Continue as Guest" button from the login screen.
<!--In theme.liquid, change:-->
<meta content="0; url=/account/login?checkout_url={{ return_url }}" http-equiv="refresh" />
<!--to -->
<meta content="0; url=/account/login?return_url={{ return_url }}" http-equiv="refresh" />
<!-- In customers/login.liquid, give the submit button an ID of customerlogin, for example: -->
@kyleaparker
kyleaparker / gist:7588995
Created November 21, 2013 20:26
Shopify: Show all numbers in pagination
{% assign count = paginate.pages %}
{% for part in (1..count) %}
<li {% if paginate.current_page == part %}class="active"{% endif %}><a href="{{ collection.url }}?page={{ forloop.index }}">{{ forloop.index }}</a></li>
{% endfor %}
@kyleaparker
kyleaparker / gist:560a3847860bace1d680
Last active July 16, 2020 21:59
[Shopify] Show multiple images per variant
<script>
jQuery(document).ready(function($){
var images = [];
{% for image in product.images %}
images.push({url: "{{ image | product_img_url: 'medium' }}", alt: "{{ image.alt }}"});
{% endfor %}
var thumbnails = $(".thumbs");
@kyleaparker
kyleaparker / gist:b108e7142be8ee105f8b
Last active November 9, 2020 16:38
Alphabetical vendor categorization
<ul>
{% assign current = "" %}
{% for product_vendor in shop.vendors %}
{% assign first_letter = product_vendor | strip_html | upcase | truncate: 1, '' %}
{% unless first_letter == current %}
<li class="vendor-letter">{{ first_letter }}</li>
{% endunless %}
<li>{{ product_vendor | link_to_vendor }}</li>
{% assign current = first_letter %}
{% endfor %}
@kyleaparker
kyleaparker / gist:5949872
Created July 8, 2013 15:32
Shopify - Show total savings on cart page
{% assign total_saving = 0 %}
{% for item in cart.items %}
{% if item.variant.compare_at_price > item.variant.price %}
{% capture saving %}{{ item.variant.compare_at_price | minus: item.variant.price }}{% endcapture %}
{% assign total_saving = saving | plus: total_saving %}
{% endif %}
...rest of cart code within for loop
{% endfor %}
Display saving: