Skip to content

Instantly share code, notes, and snippets.

View zakhardage's full-sized avatar

little desert dog zakhardage

View GitHub Profile
{% assign member_discount_code = settings.member_discount_code %}
{% assign class_discount_code = settings.class_discount_code %}
{% assign combined_discount_code = settings.combined_discount_code %}
{% if customer %}
{% assign customer_tags = customer.tags | join:',' | downcase %}
{% if customer_tags contains 'member' %}
{% assign member = true %}
{% endif %}
{% endif %}
<form action="/cart/add" method="post">
{% if product.variants.size > 1 %}
{% for variant in product.variants %}
<input type="radio" id="variant-{{ variant.title | handle }}" name="variant" value="{{ variant.id }}" />
<label for="variant-{{ variant.title | handle }}">{{ variant.title }}</label>
<br />
{% endfor %}
{% endif %}
<input type="hidden" name="id" class="product-select" value="{{ product.variants[0].id }}" />
@zakhardage
zakhardage / Shopify Random Product Order
Last active February 23, 2023 07:47
Random Product Order in Shopify
<script type="text/javascript">
function fisherYates ( myArray ) {
var i = myArray.length, j, temp;
if ( i === 0 ) return false;
while ( --i ) {
j = Math.floor( Math.random() * ( i + 1 ) );
temp = myArray[i];
myArray[i] = myArray[j];
myArray[j] = temp;
}
@zakhardage
zakhardage / Simple "Captcha" for Shopify
Created July 31, 2014 18:16
Simple "Captcha" for Shopify
// Goes in theme.liquid
{% if template contains 'contact' %}
{{ 'https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js' | script_tag }}
<script type="text/javascript">
$(document).ready(function() {
var n1 = Math.round(Math.random() * 10 + 1);
var n2 = Math.round(Math.random() * 10 + 1);
$("#question").val(n1 + " + " + n2);
$(".contact-form").submit(function (e) {
if (eval($("#question").val()) != $("#answer").val()) {
@zakhardage
zakhardage / Much much simpler option selector for Shopify
Last active July 8, 2022 09:50
Much simpler version of Shopify's option_selection.js for separating product options into their own dropdown menus.
<form action="/cart/add" method="post">
{% if product.variants.size > 1 %}
{% if product.options[0] %}
{% assign used = '' %}
<label for="select-one">{{ product.options[0] }}</label>
<select id='select-one' onchange="letsDoThis()">
{% for variant in product.variants %}
{% unless used contains variant.option1 %}
<option value="{{ variant.option1 }}">{{ variant.option1 }}</option>
{% capture used %}{{ used }} {{ variant.option1 }}{% endcapture %}
@zakhardage
zakhardage / Tiered Pricing for Shopify
Last active April 19, 2022 10:53
Shopify tiered pricing using javascript (non-app). This example has the quantity breaks controlled by theme settings.
// config -> settings.html
// Make sure you have the same number of quantity breaks as product variants
<fieldset>
<legend>Quantity Breaks</legend>
<table class="standard-table">
<tr><td>Enter quantity breaks in ascending order separated by a comma (e.g. 5, 10, 20, 50)</td><td><input type="text" name="breaks" size="50" /></td></tr>
</table>
</fieldset>
// change line 21 from
<th>Item</th>
// to
<th>SKU</th>
<th>Item</th>
// change line 30 from
{% for line_item in line_items %}
// to
{% assign line_items_by_sku = line_items | sort:'sku' %}
// change line 108 from
{% for line_item in line_items_in_shipment %}
// to
{% assign line_items_by_sku = line_items_in_shipment | sort:'sku' %}
{% for line_item in line_items_by_sku %}
@zakhardage
zakhardage / Wishlist Item Count
Created September 17, 2014 15:50
Wishlist Item Count
{% if customer %}
{% for tag in customer.tags %}
{% assign t = tag | remove:'x' %}
{% unless tags contains t %}
{% capture tags %}{{ tags }} {{ t }}{% endcapture %}
{% endunless %}
{% endfor %}
{% for collection in collections %}
{% paginate collection.products by collection.all_products_count %}