Skip to content

Instantly share code, notes, and snippets.

@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:9a3c51915953e98738d8
Created May 3, 2013 17:00
List products by product type
{% for product_type in shop.types %}
<h3>{{ product_type | link_to_type }}</h3>
{% for product in collections.all.products %}
{% if product.type == product_type %}
{{ product.title }}
{% endif %}
{% endfor %}
{% 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:
@kyleaparker
kyleaparker / gist:6122816
Created July 31, 2013 15:09
Shopify - Add percentage saved to the price in the Select callback.
---Find the select callback:
var selectCallback = function(variant, selector) {
if (variant && variant.available) {
---Add this with the select callback:
var per_saved = ((variant.compare_at_price - variant.price)/variant.compare_at_price)* 100.0;
$('.options .price').html('<strong>'+Shopify.formatMoney(variant.price, "{{shop.money_with_currency_format }}").toString().replace(',', '.') + '</strong><span class="compare_at_price"><del>' + Shopify.formatMoney(variant.compare_at_price, "{{shop.money_with_currency_format}}").toString().replace(',', '.') + '</del><br>You save ' + per_saved + '%</span>');
@kyleaparker
kyleaparker / gist:042f05a943c03ef11c67
Created October 8, 2013 00:18
Get product’s SEO information in Liquid
{% assign seo_data = product.metafields.global %}
{{ seo_data.description_tag }}
{{ seo_data.title_tag }}
{{ seo_data.metafields | to_json }}
@kyleaparker
kyleaparker / gist:7356064
Last active December 27, 2015 16:39
Inventory Quantity Table for up to two options
<div id="inventory">
<h3>Inventory Available</h3>
{% assign options1 = product.variants | map: "option1" %}
<table>
<tr>
{% if product.options.size > 1 %}<th>&nbsp;</th>{% endif %}
{% assign options1Filtered = '' %}
{% for option1 in options1 %}
{% assign option1Space = option1 | prepend: ', ' %}
{% unless options1Filtered contains option1Space %}
@kyleaparker
kyleaparker / gist:7360715
Last active December 27, 2015 17:18
Multi variant add to cart form
<div id="inventory">
<h3>Inventory Available</h3>
{% assign options1 = product.variants | map: "option1" %}
<table>
<tr>
{% if product.options.size > 1 %}<th>&nbsp;</th>{% endif %}
{% assign options1Filtered = '' %}
{% for option1 in options1 %}
{% assign option1Space = option1 | prepend: ', ' %}
{% unless options1Filtered contains option1Space %}
@kyleaparker
kyleaparker / gist:7360751
Last active December 27, 2015 17:19
Multi add to cart
{{ 'api.jquery.js' | shopify_asset_url | script_tag }}
<script type="text/javascript">
/* Enable multi add to cart function */
jQuery("#product-variants").hide();
Shopify.queue=[];$("#add").click(function(e){e.preventDefault();$(".quantity-add").each(function(){var a=$(this),id=a.attr('id'),qty=a.val();if(qty>0){Shopify.queue.push({variant_id:id,quantity_id:parseInt(qty,10)})}});if(Shopify.queue.length){Shopify.addItems()}else{alert("You have not selected anything to purchase")}});Shopify.addItems=function(){var request=Shopify.queue.shift();if(typeof request=='object'){Shopify.addItem(request.variant_id,request.quantity_id,Shopify.addItems)}else{document.location.href="/cart"}}
/* End multi add to cart function */
</script>
@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: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: -->