Skip to content

Instantly share code, notes, and snippets.

View justincron's full-sized avatar

Justin Cron justincron

View GitHub Profile
@anilmeena
anilmeena / display-variants-dropdown-shopify-collection.liquid
Created April 8, 2017 11:00
Shopify Display Multiple Variant Drop-down on Collection Page
<form action="/cart/add" method="post" style="text-align:center;">
<select name="id">
{% for variant in product.variants %}
{% if variant.available %}
<option value="{{ variant.id }}">{{ variant.title }} - {{ variant.price | money }}</option>
{% else %}
<option disabled="disabled">{{ variant.title }} - Sold Out</option>
{% endif %}
{% endfor %}
</select>
@ivandurst
ivandurst / product-grid-item.liquid
Created July 1, 2016 22:44
Shopify add a tag to a product that's on sale
{% comment %}
Add a tag to a product that's on sale. Add this in your template for displaying a product in a grid, for me it's called product-grid-item.liquid
{% endcomment %}
{% assign on_sale = false %}
{% if product.compare_at_price > product.price %}
{% assign on_sale = true %}
@rickydazla
rickydazla / product-grid-item.liquid
Last active December 17, 2017 02:16
Shopify Collection thumbnail:hover image swap
<a href="{{ product.url | within: collection }}">
{% assign imgSize = 'medium' %}
{% assign canSwap = false %}
{% if product.images.size > 1 %}
{% assign canSwap = true %}
{% assign swapImg = product.images[1] %}
{% assign swapImgSrc = swapImg.src | product_img_url: imgSize %}
{% assign swapImgAlt = swapImg.alt | escape %}
{% endif %}
<img{% if canSwap %} class="has-swap"{% endif %} src="{{ product.featured_image.src | product_img_url: imgSize }}" alt="{{ product.featured_image.alt | escape }}">
@gokulkrishh
gokulkrishh / media-query.css
Last active April 22, 2025 04:29
CSS Media Queries for Desktop, Tablet, Mobile.
/*
##Device = Desktops
##Screen = 1281px to higher resolution desktops
*/
@media (min-width: 1281px) {
/* CSS */
<!-- Ajax API -->
{{ '//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js' | script_tag }}
{{ 'api.jquery.js' | shopify_asset_url | script_tag }}
<style type="text/css">
#rv__recent_products.rv__grid{width: 100%; margin-top: 20px;}
.rv__grid .row{ display: block; clear: both;}
.rv__grid .rv__row .rv__column{ float: left; }
.rv__grid .rv__row .rv__column.rv__one{ width: 8.3%; }
.rv__grid .rv__row .rv__column.rv__two{ width: 16.66%; }
@donohfx
donohfx / multi-lang.liquid
Last active December 17, 2017 00:41
Multiple Languages + Currencies
<!-- This is an example of automatic currency switching based on IP as well as language selection using Langify and redirects.
All domains should be set up in Langify with their appropriate languages. I'd recommend placing this code in its own snippet
and including it near the </body> tag in your theme.liquid
Dependencies:
- currencies.js (https://github.com/carolineschnapp/currencies)
- Langify (https://apps.shopify.com/langify)
- A Shopify Store (well, should work anywhere, but only tested on Shopify)
-->
@lukeburford
lukeburford / Shopify random blog post (Liquid server-side method)
Last active February 16, 2021 10:36
Display random post from a Shopify blog, for example on the store homepage. Shopify caches it's pages so a homepage refresh will not show a new post, but adding an item to the cart and returning to the homepage will. Based on: http://wiki.shopify.com/Featuring_one_randomly_picked_product
{% capture index %}{{ 'now' | date: '%S' | times: collections.frontpage.products.size | divided_by: 60 }}{% endcapture %}
{% for article in blogs.blog-name.articles offset:index limit:1 %}
<a href="{{article.url}}">{{ article.title }}</a>
{% endfor %}
@strack
strack / A-Pen-by-Isaac-Strack.markdown
Last active December 21, 2015 14:58
A Pen by Isaac Strack.
@PaulKinlan
PaulKinlan / criticalcss-bookmarklet-devtool-snippet.js
Last active March 12, 2025 01:22
CriticalCSS Bookmarklet and Devtool Snippet.js
(function() {
var CSSCriticalPath = function(w, d, opts) {
var opt = opts || {};
var css = {};
var pushCSS = function(r) {
if(!!css[r.selectorText] === false) css[r.selectorText] = {};
var styles = r.style.cssText.split(/;(?![A-Za-z0-9])/);
for(var i = 0; i < styles.length; i++) {
if(!!styles[i] === false) continue;
var pair = styles[i].split(": ");
@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: