Skip to content

Instantly share code, notes, and snippets.

View carolineschnapp's full-sized avatar

Caroline carolineschnapp

  • Shopify
  • Montreal
View GitHub Profile
@carolineschnapp
carolineschnapp / gist:3173581
Last active August 31, 2016 19:26
Un-minified size-chart.liquid snippet
{% comment %}
We include this in theme.liquid before the </body> tag.
This adds a Size Chart link on the right of all Size drop-downs
on all product pages.
Code by Caroline Schnapp.
Re-use, be merry, amuse yourself and marry your muse.
{% endcomment %}
{% if template contains 'product' %}
@carolineschnapp
carolineschnapp / size-chart.liquid
Last active November 28, 2018 16:56
size-chart.liquid snippet
{% if template contains 'product' %}
{% assign size_options = 'size,taille' | split: ',' %}
{% assign size_chart_text_link = 'Size chart' %}
{% assign has_size = false %}
{% assign size_index = 0 %}
{% for option in product.options %}
{% assign downcased_option = option | downcase %}
{% if has_size == false and size_options contains downcased_option %}
{% assign has_size = true %}
{% assign size_index = forloop.index0 %}
@carolineschnapp
carolineschnapp / gist:2292361
Created April 3, 2012 14:20
How to filter a collection by vendor
<!-- add the vendor as product tag to product then use this code in collection.liquid -->
<!-- if we are on a collection page that is either custom or smart -->
{% if collection.url != blank %}
<h4>Shop by vendor:</h4>
<ul>
{% for product_vendor in collection.all_vendors %}
<li>
{% if current_tags contains product_vendor %}
<a class="active" href="{{ collection.url }}">{{ product_vendor }}</a>
{% else %}
{% assign shipping_section = '' %}
{% assign blog = blogs.faq %}
{% paginate blog.articles by 100 %}
{% for article in blog.articles %}
{% if article.tags contains 'Shipping' %}
{% capture shipping_section %}{{ shipping_section }}<li>{{ article.title | link_to: article.url }}</li>{% endcapture %}
{% endif %}
{% endfor %}
{% endpaginate %}
@carolineschnapp
carolineschnapp / gist:2052746
Created March 16, 2012 21:14
Showing or hiding a back-order message
var selectCallback = function(variant, selector) {
if (variant && variant.available) {
if (variant.inventory_management != '' && variant.inventory_quantity < 0) {
$('.backorder').show();
}
else {
$('.backorder').hide();
}
$("input#add").removeClass("disabled").removeAttr("disabled");
$("h2#price span").html(Shopify.formatMoney(variant.price, "{{ shop.money_format }}"));
@carolineschnapp
carolineschnapp / gist:2031244
Created March 13, 2012 20:10
2 level-deep drop-down menus using naming convention for both levels
<ul>
{% for link in linklists.main-menu.links %}
<li class="{% if forloop.first %}first{% elsif forloop.last %}last{%endif%}">
{% assign child_list_handle = link.title | handle %}
{% if linklists[child_list_handle].links != blank %}
<div class="has-dropdown">
<a href="{{ link.url }}" class="clearfix">
<span class="nav-label">{{ link.title }}</span>
<span class="nav-arrow"></span>
</a>
@carolineschnapp
carolineschnapp / gist:2013774
Created March 10, 2012 22:50
Shipment Day
{% capture day_of_the_week %}{{ created_at | date: '%A' }}{% endcapture %}
{% if day_of_the_week == 'Saturday' or day_of_the_week == 'Sunday' or day_of_the_week == 'Monday' or day_of_the_week == 'Tuesday' %}
Your order will ship this coming Wednesday.
{% else %}
Your order will ship this coming Monday.
{% endif %}
@carolineschnapp
carolineschnapp / gist:1962629
Created March 2, 2012 23:59
Drop-down menu using a select element and a link list
<form name="shop-by-category">
<select onchange="if (this.value !== '') window.location = this.value;">
<option value="">Shop by Category</option>
{% for link in linklists[shop-by-category].links %}
<option name="collection" value="{{ link.url }}"{% if link.active %} selected="selected"{% endif %}>{{ link.title }}</option>
{% endfor %}
</select>
</form>
@carolineschnapp
carolineschnapp / gist:1961517
Created March 2, 2012 21:25
Add this at the bottom of cart.liquid to auto-save your cart attributes
<script type="text/javascript" charset="utf-8">
//<![CDATA[
jQuery(function() {
jQuery(window).unload(function() {
var params = {
type: 'POST',
url: '/cart/update.js',
data: jQuery('form[action="/cart"]').serialize(),
dataType: 'json',
async: false