Skip to content

Instantly share code, notes, and snippets.


Stewart Knapman stewartknapman

View GitHub Profile
stewartknapman / product.liquid
Last active Jul 11, 2022
Basic accordion for Shopify product
View product.liquid
{% comment %}
Liquid will output content, split on h3s like this:
<div class="accordian">
<h5><a href="#free-shipping" data-accordian-action>Free & Fast USA Shipping <span>+</span></a></h5>
<p id="free-shipping" data-accordian-target>All orders are shipped through USPS. We pride ourselves on fast delivery. Orders typically arrive within 2-5 business days. You will receive an email with tracking information when your order is ready to ship.</p>
<h5><a href="#international-shipping" data-accordian-action>International Shipping <span>+</span></a></h5>
<p id="international-shipping" data-accordian-target>International shipping rates vary based on item(s). Shipping rates can be seen on the checkout page. International orders typically arrive within 7-10 business days, but can vary with customs clearance in each country. </p>
stewartknapman / checkout.scss
Last active Apr 10, 2022
Pull web fonts into Shopify's checkout from the theme settings, through a sass file located outside the theme directory. Why? ... because its cool.
View checkout.scss
* Checkout.scss sits outside the Shopify theme folder so that we can pull in Boostrap and our checkout reset via scss imports.
* This will be compiled into checkout.css.liquid and saved in our theme assets folder.
* As this will be compiled into liquid we need to escape our liquid tags to prevent our compiler having a meltdown.
* You need to do this across two files otherwise you'll end up with an empty import rule at the top of your checkout.css.liquid
// import the compiled font_import.css.liquid from our assets folder.
// note the escaped liquid.
stewartknapman / shopify-money.js
Created Feb 27, 2017
The Shopify.formatMoney method extracted from option_selection.js for stand-alone purposes.
View shopify-money.js
var Shopify = Shopify || {};
// ---------------------------------------------------------------------------
// Money format handler
// ---------------------------------------------------------------------------
Shopify.money_format = "${{amount}}";
Shopify.formatMoney = function(cents, format) {
if (typeof cents == 'string') { cents = cents.replace('.',''); }
var value = '';
var placeholderRegex = /\{\{\s*(\w+)\s*\}\}/;
var formatString = (format || this.money_format);
stewartknapman / Shipping_rate_by_product_tag.rb
Created Nov 28, 2021
Shopify script to show shipping rates if products have certain tags
View Shipping_rate_by_product_tag.rb
# ================================ Customizable Settings ================================
# ================================================================
# Show Rate(s) for Product Tag
# If we have a product with matching tag, the entered rate(s) will be
# shown, and all others will be hidden. Otherwise, the entered
# rate(s) will be hidden.
# - 'product_tag_match_type' determines whether we look for the
# product to be tagged with any of the entered tags or not.
View Find what code changed the

Have you ever tried to track down which piece of javascript modified the DOM? Use a mutationObserver to monitor the DOM for changes. Then run console.trace() inside the callback. This will log a stack trace all the way back to the code that did the DOM modification. Basically copy and paste this code.

View accordian.js
(function () {
if (!document.querySelector && !window.addEventListener && !("classList" in document.createElement("p"))) return;
var ready = function (callback, ctx) {
if (typeof callback !== 'function') return;
if (document.readyState !== "loading") {
} else {
document.addEventListener("DOMContentLoaded", function () {
stewartknapman /
Last active Mar 19, 2021
Automagically add a free product to the customers cart when they purchase a certain product(s)

We want to automagically add a free product to the customers cart when they purchase a certain product(s).

Note: This code will likely need to be adapted to suit your theme, however it should be enough to discribe the concept.

Add the free product

  1. Define the free product and which products can add it. We create some theme setting that allow us to pick the free product and a collection of products that can add it. e.g. and
stewartknapman / style.liquid.scss
Last active Dec 2, 2020
Compile sass into liquid
View style.liquid.scss
// Escape Liquid in scss.
// Expected output:
// a{
// color: {{ }};
// }
color: #{'{{ }}'};
View Font names to numbers
100 ultra light/thin
200 light/thin
300 book/light
400 roman/normal
500 med
600 semibold
700 bold
800 heavy
900 black
stewartknapman / Tabs.scss
Last active Jun 13, 2019
Tabs for use with Debut
View Tabs.scss
.description-tab__header {
padding-top: 1.5em;
.no-js &:first-child {
padding-top: 0;
.has-tabs {
.description-tabs {
position: relative;
@include display-flexbox();