Skip to content

Instantly share code, notes, and snippets.

View git-willie's full-sized avatar

Willie git-willie

View GitHub Profile
@git-willie
git-willie / variant-specs.liquid
Created November 29, 2016 01:09
Break down each product variant into a label and value
{% unless item.variant.title contains 'Default' %}
{% for i in (1..item.product.options.size) %}
<small class="specs">
{% case i %}
{% when 1 %}
<span>{{ item.product.options.first }}</span> {{ item.variant.option1 }}
{% when 2 %}
{% if item.product.options.size == 2 %}
<span>{{ item.product.options.last}}</span> {{ item.variant.option2 }}
{% else %}
@git-willie
git-willie / related-products-by-product-handle.liquid
Created November 29, 2016 19:04
Related products by using tag with a product handle. For example, related-hdmi-cable
<ul class="top-tier no-bullets">
{% for link in linklists.shop.links %}
{% assign second_tier_list_handle = link.title | handleize %}
{% if linklists[second_tier_list_handle].links != blank %}
<li class="grid__item{% if link.active %} site-nav--active{% endif %}">
<span class="h4 grid__item">{{ link.title }}</span>
<ul class="second-tier no-bullets">
{% for secondTierLink in linklists[second_tier_list_handle].links %}
{% assign third_tier_list_handle = secondTierLink.title | handleize %}
<div class="social-share-btns">
<span style="display: inline-block">Share</span>
<a href="https://www.facebook.com/sharer/sharer.php?u={{product.url}}&title={{product.title}}" onclick="window.open(this.href, 'mywin','left=20,top=20,width=500,height=500,toolbar=1,resizable=0'); return false;"><i class="fa fa-facebook-square"></i></a>
<a href="http://twitter.com/home?status={{ product.title }}+{{shop.url}}{{product.url}}" onclick="window.open(this.href, 'mywin','left=20,top=20,width=500,height=500,toolbar=1,resizable=0'); return false;"><i class="fa fa-twitter"></i></a>
<a href="http://pinterest.com/pin/create/bookmarklet/?media=https:{{ product.featured_image | product_img_url: 'grande' }}&url={{shop.url}}{{product.url}}&is_video=false&description={{ product.title }}" onclick="window.open(this.href, 'mywin','left=20,top=20,width=500,height=500,toolbar=1,resizable=0'); return false;"><i class="fa fa-pinterest"></i></a>
<a href="https://plus.google.com/share?url={{shop.url}}{{product.url}}" oncl
@git-willie
git-willie / load-ajax-content.php
Created November 29, 2016 20:12
[Wordpress] Load content via Ajax
// *** Load gallery on division template via Ajax ***
function load_ajax_content () {
$pid = array( 'p' => $_POST['post_id'], 'post_type' => 'gallery' );
$the_query = new WP_Query( $pid );
if ($the_query->have_posts()) {
while ( $the_query->have_posts() ) {
$the_query->the_post();
$images = get_field('photos');
@git-willie
git-willie / custom-excerpt.php
Created December 14, 2016 19:24
// Custom Excerpt
// Custom Excerpt
function excerpt($limit) {
$excerpt = explode(' ', get_the_excerpt(), $limit);
if (count($excerpt)>=$limit) {
array_pop($excerpt);
$excerpt = implode(" ",$excerpt) . ' &hellip;';
} else {
$excerpt = implode(" ",$excerpt);
}
$excerpt = preg_replace('`[[^]]*]`','',$excerpt);
@git-willie
git-willie / search-autocomplete.liquid
Created January 12, 2017 19:35
Shopify search auto complete snippet
<script>
$(function() {
// Current Ajax request.
var currentAjaxRequest = null;
// Grabbing all search forms on the page, and adding a .search-results list to each.
var searchForms = $('form[action="/search"]').css('position','relative').each(function() {
// Grabbing text input.
var input = $(this).find('input[name="q"]');
// Adding a list for showing search results.
var offSet = input.height();
@git-willie
git-willie / ajaxLoadProducts.js
Last active May 24, 2019 18:58
Infinite load products on scroll
var ajaxLoadPageIndex = 1;
function ajaxLoadProducts() {
if ($(document).height() - 800 < ($(document).scrollTop() + $(window).height())) {
collectionURL = $('.collection-main').attr('data-collection-url');
collectionPages = $('.collection-main').attr('data-collection-pages');
++ajaxLoadPageIndex;
if (ajaxLoadPageIndex <= collectionPages) {
$.ajax({
@git-willie
git-willie / finishCustomization.js.liquid
Created May 24, 2019 18:57
Bundle products and add all to cart after customization
$(document).on('click', '#finish-customization', function(e){
e.preventDefault();
bundle_prefix = "{{ product.handle | replace: '-','_' }}";
bundle_id = Math.floor((Math.random() * 100000) + 1);
$('input[name="properties[Custom Product ID]"]').val(bundle_prefix+'_'+bundle_id);
$(this).find('span').html('Adding to Cart');
var $result = decodeURIComponent($('#AddToCartForm-{{ section.id }}').serialize());
$result = $result.split('&');
@git-willie
git-willie / saleMotivator.js
Created May 26, 2019 21:57
Dynamic sales motivator message
// Display motivator message
ShopifyAPI.saleMotivator = function(cart, cart_motivator_goal, motivator_msg_selector) {
var cart_subtotal = parseFloat(cart.total_price / 100).toFixed(2);
var cart_motivator_goal = cart_motivator_goal;
var cart_motivator_goal_remaining = parseFloat(cart_motivator_goal - cart_subtotal).toFixed(2);
var motivator_msg = motivator_msg_selector;
if (cart_subtotal == 0) {
motivator_msg.html('FREE SHIPPING ON ORDERS OVER $' + cart_motivator_goal);
} else {
if (cart_subtotal >= cart_motivator_goal) {