Created
October 30, 2014 11:03
-
-
Save lucased/b470545f531ac3e181eb to your computer and use it in GitHub Desktop.
Shopify - Add product to cart automatically
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (typeof Shopify === 'undefined') var Shopify = {}; | |
Shopify.cart = {{ cart | json }}; | |
Shopify.toAdd = 378589397; | |
var surchargeInCart = false; | |
var total = 2507; // total in cents. | |
for (var i=0; i<Shopify.cart.items.length; i++) { | |
if (Shopify.cart.items[i].id === Shopify.toAdd) { | |
surchargeInCart = true; | |
total -= Shopify.cart.items[i].line_price; | |
} | |
} | |
if (!surchargeInCart && total < 5000 && total >= 0) { | |
var params = { | |
type: 'POST', | |
url: '/cart/add.js', | |
data: 'quantity=1&id=' + Shopify.toAdd, | |
dataType: 'json', | |
success: function(line_item) { | |
window.location.href = '/cart'; | |
} | |
}; | |
jQuery.ajax(params); | |
} | |
if (surchargeInCart && total >= 5000 || surchargeInCart && total === 0) { | |
window.location.href = '/cart/change?id=378589397&quantity=0'; | |
} | |
// Hiding the gift-wrap quantity box and remove button. | |
jQuery(function() { | |
jQuery('#updates_' + Shopify.toAdd).hide().parents('li,tr').find('a:last').hide(); | |
}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Anyway to adjust the code above to automatically add a "processing and handling" fee of $19.95 to the cart when they add a product?
(optional)And maybe also have a small image thumb to represent what the fee covers there as well?
Thanks for any help!