Skip to content

Instantly share code, notes, and snippets.

View richietyler's full-sized avatar

Richie Tyler richietyler

View GitHub Profile
@richietyler
richietyler / available-sizes.liquid
Last active July 30, 2019 02:05
Display available sizes beneath product on collection page (Shopify). Relies on Dylan Hunt's tutorial on displaying colour variants as separate products (https://dylanjh.com/blogs/15-show-all-colors-of-a-product-as-separate-products-on-the-collection-page)
{% comment %}Print 'colour' variable to show variant loop is working{% endcomment %}
<p><strong>{{ colour }}</strong></p>
{% for product_option in product.options_with_values %}
{% if product_option.name == 'Colour' %}
{% if product_option.values contains colour %}
{% assign proceed = true %}
{% comment %}Print confirmation that test has passed{% endcomment %}
<p>Yep</p>
{% for opt in product.options_with_values %}
{% if opt.name == 'Size' %}
{% for var in product.variants %}
{% if var.available %}
{% assign spanclass='size-label'%}
{% else %}
{% assign spanclass='size-label size-sold'%}
{% endif %}
{% if opt.values contains var.option1 %}
@richietyler
richietyler / usStateCodesToNames.js
Last active February 4, 2022 09:21
USA State codes to State Names function
// Simple function to convert US 2-letter state codes to capitalised state names
function usStateCodesToNames(stateCode) {
const code = stateCode.toLowerCase();
if (code === "al") {
return "Alabama"
} else if (code === "ak") {
return "Alaska"
} else if (code === "az") {
return "Arizona"
@richietyler
richietyler / caProvinceCodesToName.js
Created October 28, 2022 00:18
Simple function to convert Canadian province/territory codes to names
function caProvinceCodesToNames(stateCode) {
const code = stateCode.toLowerCase();
if (code === "ab") {
return "Alberta"
} else if (code === "bc") {
return "British Columbia"
} else if (code === "mb") {
return "Manitoba"
} else if (code === "nb") {
return "New Brunswick"