Skip to content

Instantly share code, notes, and snippets.

@kyleaparker

kyleaparker/gist:7360751

Last active Dec 27, 2015
Embed
What would you like to do?
Multi add to cart
{{ 'api.jquery.js' | shopify_asset_url | script_tag }}
<script type="text/javascript">
/* Enable multi add to cart function */
jQuery("#product-variants").hide();
Shopify.queue=[];$("#add").click(function(e){e.preventDefault();$(".quantity-add").each(function(){var a=$(this),id=a.attr('id'),qty=a.val();if(qty>0){Shopify.queue.push({variant_id:id,quantity_id:parseInt(qty,10)})}});if(Shopify.queue.length){Shopify.addItems()}else{alert("You have not selected anything to purchase")}});Shopify.addItems=function(){var request=Shopify.queue.shift();if(typeof request=='object'){Shopify.addItem(request.variant_id,request.quantity_id,Shopify.addItems)}else{document.location.href="/cart"}}
/* End multi add to cart function */
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment