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 / convertToShoppingList.html
Created November 23, 2020 05:21
Convert UL > LI into a custom shopping list
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Convert UL > LI into a custom shopping list</title>
</head>
<body>
<h2>Please select total 6 items</h2>
<ul id="choices-list" data-max-choices="6">
@git-willie
git-willie / productsInfiniteLoad.js
Created November 18, 2020 01:46
Infinitely loads products on to a collection page
$(document).ready(function() {
var collectionURL = $('.collection-main').attr('data-collection-url');
var collectionPages = $('.collection-main').attr('data-collection-pages');
var ajaxLoadPageIndex = 2;
var ajaxIsRunning = false;
$(window).scroll(function(){
if ($(document).scrollTop() > 500) {
infiniteLoadProducts();
}
@git-willie
git-willie / estimatedDeliveryTime.js
Created May 26, 2019 22:19
Displaying estimated shipping delivery date (based on client's shipping criteria)
function estimatedDeliveryTime(){
var timeStamp_1 = new Date(),
timeStamp_2 = new Date(),
dayNames = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],
monthNames = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],
estOffset = -240, // EST offset in minutes
customerTimezoneOffset = timeStamp_1.getTimezoneOffset(),
utc = (timeStamp_1.getHours() * 60) + timeStamp_1.getMinutes() + customerTimezoneOffset,
customerEstTime = utc + estOffset, // Customer time in EST
shippingCutoffTime = 16 * 60; // 4pm EST in minutes
@git-willie
git-willie / warranty-addon.liquid
Created May 26, 2019 22:16
Product price based warranty addon
{% assign warranty = all_products['warranty'] %}
{% assign warrantyDesc = warranty.description | strip_html %}
{% for i in (1..100) %}
{% assign warranty_max_price = i | plus: 1 | times: 1000 %}
{% if product.price <= warranty_max_price %}
{% assign warranty_price = warranty_max_price | minus: 1 | divided_by: 10 %}
{% break %}
{% elsif product.price > warranty_max_price %}
{% assign warranty_price = 10099 %}
@git-willie
git-willie / upsell-products.liquid
Created May 26, 2019 22:10
Upsell products similar to Amazon's
{% assign current_product_handle = product.handle %}
{% assign upsell_product_col = 'col-xs-4' %}
{% assign sum = product.price %}
{% assign number_of_upsell_products = 0 %}
{% for upsell_product in upsell_collection.products limit: 4 %}
{% unless upsell_product.handle == current_product_handle %}
{% assign sum = sum | plus: upsell_product.price %}
{% endunless %}
{% assign number_of_upsell_products = forloop.index %}
{% endfor %}
@git-willie
git-willie / js-filtered-products.liquid
Created May 26, 2019 22:01
Ajax filtering products with Handlebar JS
<script>
var product_json = {{ products | json }};
function getFilterProducts(tags){
buildFilteredProducts(filterProducts(product_json, tags));
}
function filterProducts(products, tags) {
var filteredProducts = products.filter(function(product){
var total_tags = tags.length;
@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) {
@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 / 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 / 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();