Skip to content

Instantly share code, notes, and snippets.

View dylanjhunt's full-sized avatar

Dylan Hunt dylanjhunt

View GitHub Profile
<div id="variant-inventory">
{% assign total = 0 %}
{%for variant in product.variants %}
{% capture i %}{{ total | plus:variant.inventory_quantity }}{%endcapture%}
{% assign total = i %}
{%endfor%}
{% unless total == '0' %}
Only {{ total }} left
{% endunless %}
</div>
@dylanjhunt
dylanjhunt / gist:a5b743e91fe0d35e80d2eb1cb591f606
Last active November 10, 2017 16:02
Black Friday Cyber Monday Shopify Scripts for Free gifts
min_discount_order_amount = Money.new(cents:100) * 75
discount_products = [xxxxxxxxxx, xxxxxxxxxx, xxxxxxxxxx, xxxxxxxxxx]
total = Input.cart.subtotal_price_was
discount = if total > min_discount_order_amount
1
else
0
end
message = "You've earned a free gift"
did_discount = false
@dylanjhunt
dylanjhunt / gist:b6078c4b756e033d667830ad3176a947
Created March 7, 2018 15:59
Smooth Scrolling Javascript for Shopify
$('a[href*="#"]')
.not('[href="#"]')
.not('[href="#0"]')
.click(function(event) {
if (
location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '')
&&
location.hostname == this.hostname
) {
var target = $(this.hash);
<iframe id="vimeo_player" src="https://player.vimeo.com/video/257992348?autoplay=1&loop=1&autopause=0&muted=1" width="500" height="281" frameborder="0" muted webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
@dylanjhunt
dylanjhunt / Filter by size in stock shopify. Step 1 full guide at dylanjh.com
Last active August 3, 2022 12:18
Filter by size in stock shopify. Step 1 full guide at https://dylanjh.com
{% assign sizes = '' %}
{% for product in products limit: limit %}
{% for variant in product.variants %}
{% if variant.available %}
{% assign sizes = sizes | append: variant.options[1] | append: '_' %}
{% endif %}
{% endfor %}
{% endfor %}
{% assign sizesArr = sizes | split: '_' | uniq %}
@dylanjhunt
dylanjhunt / Filter by size in stock Shopify step 2
Last active August 28, 2020 01:17
Filter by size in stock Shopify step 2
{% assign sizes = '' %}
{% assign outofstock = false %}
{% for tag in current_tags %}
{% if tag == 'XS' or tag == 'S' or tag == 'M' or tag == 'L' or tag == 'XL' %}
{% assign outofstock = true %}
{% endif %}
{% endfor %}
{% for variant in product.variants %}
{% if variant.available %}
@dylanjhunt
dylanjhunt / Show all colors for a product as separate products on collection page
Last active March 11, 2022 16:59
Show all colors for a product as separate products on collection page
{% for product in collection.products %}
{% assign color_active = false %}
{% for option in product.options %}
{% if option == 'Color' %}
{% assign color_active = true %}
{% endif %}
{% endfor %}
{% if product.variants.size > 1 and color_active == true %}
{% for option in product.options %}
{% if option == 'Color' %}
@dylanjhunt
dylanjhunt / gist:b0fb32ec1d48d27da59a4da93798044f
Created December 17, 2018 14:57
$X Off if cart is over $Y Shopify Script - https://dylanjh.com guides
min_discount_order_amount = Money.new(cents:100) * 30
total = Input.cart.subtotal_price_was
discount = if total > min_discount_order_amount
500
else
0
end
message = "My message"
Input.cart.line_items.each do |line_item|
@dylanjhunt
dylanjhunt / gist:d5b29786ed597754f7df107b02f9a246
Created December 17, 2018 14:59
Variable discount Shopify Script - https://dylanjh.com guides
min_discount_order_amount = Money.new(cents:100) * 50
min_discount_order_amount_2 = Money.new(cents:100) * 100
total = Input.cart.subtotal_price_was
discount = if total > min_discount_order_amount_2
1000
elsif total > min_discount_order_amount
500
else
0
end
@dylanjhunt
dylanjhunt / Show all variants as separate products on the collection page on the Brooklyn Theme
Created March 7, 2019 13:53
Show all variants as separate products on the collection page on the Brooklyn Theme - https://dylanjh.com
{% if product.variants.size > 1 %}
{% for option in product.options %}
{% if option == 'Color' %}
{% assign index = forloop.index0 %}
{% assign colorlist = '' %}
{% assign color = '' %}
{% for variant in product.variants %}
{% capture color %}
{{ variant.options[index] }}
{% endcapture %}