Skip to content

Instantly share code, notes, and snippets.

View drabbytux's full-sized avatar

David Little drabbytux

View GitHub Profile
@drabbytux
drabbytux / limit-cart-quantities-to-in-stock-items.md
Last active November 27, 2020 16:19
Limit cart quantities to in-stock items
layout title description nav
default
Limit cart quantities to in-stock items
You can prevent your customers from adding larger quantities to the cart than you have in stock at your online Shopify store.
group
products
@drabbytux
drabbytux / get-customization-information-for-products.js
Last active June 22, 2017 00:25 — forked from carolineschnapp/gist:11167400
Get custom information for product javascript for theme.js
jQuery(function($) {
$('form[action="/cart/add"]').submit(function() {
var formIsValid = true;
var message = "Please fill this out and you will be able to add the item to your cart.";
$(this).find('[name^="properties"]').filter('.required, [required="required"]').each(function() {
$(this).removeClass('error');
if (formIsValid && $(this).val() == '') {
formIsValid = false;
message = $(this).attr('data-error') || message;
$(this).addClass('error');
@drabbytux
drabbytux / recommend-related-products.md
Last active March 18, 2018 15:31
Recommend related products to your customers
@drabbytux
drabbytux / pick-an-option-product-template.js
Created December 11, 2016 00:37
Make 'Pick and Option" by Default for product-template.liquid
<script>
var productOptions = [];
{% for option in product.options %}
var optionObj = {};
optionObj[ {{ forloop.index0 }} ] = "{{ product.options[forloop.index0] }}";
productOptions.push(optionObj);
{% endfor %}
</script>
@drabbytux
drabbytux / pick-an-option-theme.js
Last active March 11, 2017 12:40
Make 'Pick an option' the default choice Javascript for theme.js
$(document).ready(function() {
if( typeof(productOptions ) != "undefined" ){
for(i=0;i<productOptions.length;i++) {
if (['a', 'e', 'i', 'o', 'u'].indexOf(productOptions[i][i].substr(0, 1).toLowerCase()) !== -1 ) {
$('.single-option-selector:eq('+ i +')')
.filter(function() {
return $(this).find('option').length > 1
})
.prepend('<option value="">Pick an ' + productOptions[i][i] + '</option>')
.val('')
@drabbytux
drabbytux / pick-an-option.liquid
Created December 10, 2016 21:07 — forked from carolineschnapp/pick-an-option.liquid
Make 'Pick an option' the default choice in product drop-down menus
{% comment %}
See https://docs.shopify.com/themes/customization/products/how-to-add-a-pick-an-option-to-drop-downs
{% endcomment %}
{% unless product.selected_variant %}
{% if product.variants.size > 1 %}
<script>
var $addToCartForm = $('form[action="/cart/add"]');
if (window.MutationObserver && $addToCartForm.length) {
if (typeof observer === 'object' && typeof observer.disconnect === 'function') {
@drabbytux
drabbytux / how-to-add-a-pick-an-option-to-drop-downs.md
Last active March 6, 2017 15:21
Make 'Pick an option' the default choice in product drop-down menus
layout title sidebar_title description nav
default
Make 'Pick an option' the default choice in product drop-down menus
Make 'Pick an option' the default choice for drop-downs
Quick customization to your theme to let customers know there are variants.
group
products
@drabbytux
drabbytux / make-image-change-javascript.js
Last active September 22, 2020 22:48
Make Image Change javascript (for theme.js file)
$(document).ready(function() {
thumbnails = $('img[src*="/products/"]').not(':first');
if (thumbnails.length) {
thumbnails.bind('click', function() {
var arrImage = $(this).attr('src').split('?')[0].split('.');
var strExtention = arrImage.pop();
var strRemaining = arrImage.pop().replace(/_[a-zA-Z0-9@]+$/,'');
var strNewImage = arrImage.join('.')+"."+strRemaining+"."+strExtention;
if (typeof variantImages[strNewImage] !== 'undefined') {
productOptions.forEach(function (value, i) {
@drabbytux
drabbytux / make-image-change-variant-sections
Created December 10, 2016 20:22
make image change variant sections
{% comment %}
Place this in your product.liquid template, at the bottom.
{% endcomment %}
{% if product.variants.size > 1 %}
<script>
var variantImages = {},
thumbnails,
variant,
variantImage,
optionValue,
@drabbytux
drabbytux / select-variants-by-clicking-images.md
Last active December 10, 2016 20:29
Select product variants by clicking their images
layout title sidebar_title description nav
default
Select product variants by clicking their images
Select variants by clicking their images
Enable customers to select a product variant by clicking its image on your online Shopify store.
group
products