Skip to content

Instantly share code, notes, and snippets.

@Cam
Cam / cart.liquid
Last active March 10, 2021 12:35
Shopify automatic discounts in cart without Plus sample code
<script>if (typeof Shopify === "undefined") var Shopify = {}; Shopify.cart = {{ cart | json }};</script>
{% assign all_items_count = 0 %}
{% assign discount_line_total = 0 %}
{% if cart.item_count > 0 %}
{% for item in cart.items %}
{{ item.title }}
@Cam
Cam / object_properties.liquid
Created October 30, 2019 06:16
Get properties from global objects in liquid for Shopify
{%- assign object = block.settings.url -%}
{%- if object -%}
{%- if object.type == 'page_link' -%}
{%- assign object = block.settings[link] | remove: '/pages/' -%}
{%- assign title = pages[object].title -%}
{%- elsif object.type == 'collection_link' -%}
{%- assign object = block.settings[link] | remove: '/collections/' -%}
{%- assign title = collections[object].title -%}
{%- elsif object.type == 'product_link' -%}
@Cam
Cam / share.liquid
Last active September 17, 2018 09:01
Handy ‘lite’ Shopify sharing code
<!-- Sharing is caring, with love from Cam -->
{% if template contains 'product' %}
<ul class="social-sharing inline-list">
<li title="Share on Twitter"><a target="_blank" href="https://twitter.com/intent/tweet?text={{ product.title | truncate: 30 }}&url=http%3A%2F%2F{{ shop.domain }}{{ product.url | replace: '/', '%2F' }}&via=YOURTWITTERNAME">Share on Twitter</a></li>
<li title="Share on Facebook"><a target="_blank" href="http://www.facebook.com/sharer/sharer.php?u=http://{{ shop.domain }}{{ product.url }}">Share on Facebook</a></li>
<li title="Share on Google+"><a target="_blank" href="https://plus.google.com/share?url=http://{{ shop.domain }}{{ product.url }}">Share on Google+</a></li>
<li title="Share on LinkedIn"><a target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&url=http://{{ shop.domain }}{{ product.url }}&title={{ product.title | truncate: 30 }}&summary={{ product.description | strip_html | truncate: 240 }}&source=http://{{ shop.domain }}{{ product.url }}">Share
{% comment %}
To add a companion product to the cart automatically if a primary product is in cart:
1. Create a new link list under your Navigation tab.
2. In that link list, make the first link point to companion product.
3. Copy your link list handle where indicated at line 9
4. Set the minimum cart total required for the bonus product on line 10
{% endcomment %}
{% assign linklist = linklists['put-your-link-list-handle-here'] %}
{% assign min_total = 100 %}
@Cam
Cam / url-var.js
Created October 6, 2016 23:16
Get All URL Parameters
// Check each URL parameter
function GetURLParameter(sParam)
{
var sPageURL = window.location.search.substring(1);
var sURLVariables = sPageURL.split('&');
for (var i = 0; i < sURLVariables.length; i++)
{
var sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] == sParam)
{
@Cam
Cam / pre-order-form.snippet
Created July 8, 2015 03:21
Shopify Pre-Order Matrix
{% assign preorders = 0 %}
{% for item in cart.items %}
{% if item.product.tags contains 'coming-soon' %}
{% capture preorders %}{{ preorders | plus: 1 }}{% endcapture %}
{% endif %}
{% endfor %}
{% if cart.item_count == 0 %}
{% if product.tags contains 'coming-soon' %}
<input type="submit" name="add" id="add" value="Pre-order Now" class="purchase button">
@Cam
Cam / brands.liquid
Last active August 29, 2015 14:13
Basic Shopify Brand Image Link List
<ul class="brands">
{% for link in linklists.brands.links %}
{% unless link.object.image.src == blank %}
<li>
<a href="{{ link.object.url }}" title="{{ link.object.title | escape }}">
<img src="{{ link.object.image.src | collection_img_url: 'medium' }}" alt="{{ link.object.title | escape }}" />
</a>
</li>
{% endunless %}
{% endfor %}
@Cam
Cam / gist:f66fb1f60345acb3639a
Last active August 29, 2015 14:12
Fancy Safari Extension
<!DOCTYPE html>
<html>
<title>Fancy</title>
<script>
// Watch the extension for a trigger
safari.application.addEventListener("command", performCommand, false);
// Do something when triggered
function performCommand(event) {
// Pass that command we created before to this script
{% assign linklist = linklists['order-form'] %}
<form>
<table cellspacing="0" cellpadding="0" border="1">
<tbody>
<tr id="cart-headlines">
<td class="cart-thumb">&nbsp;</td>
<td class="cart-title">Product Title</td>
<td class="cart-unitprice">Price</td>
<td class="cart-quantity">Quantity</td>
</tr>