Skip to content

Instantly share code, notes, and snippets.

@nmanousos
Last active December 11, 2015 04:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nmanousos/4549391 to your computer and use it in GitHub Desktop.
Save nmanousos/4549391 to your computer and use it in GitHub Desktop.
Radiance quick-add
<script>
$(function() {
$('.product-grid-item').append('<a href="/cart" style="margin-top:5px;" class="btn quick-add">Add to Cart</a>')
$('.quick-add').click(function(e){
e.preventDefault();
var quick_add_item = this
if($(quick_add_item).text() == 'View cart') {
window.location = $(quick_add_item).attr('href')
} else {
var quick_add_id = $(this).parent().attr('id').split('product-').join('')
var hostname = document.location.hostname;
var protocol = document.location.protocol;
$.ajax({
type: 'POST',
url: protocol+'//'+hostname+'/cart/add.js?quantity=1&id='+quick_add_id,
dataType: 'json',
success: function(){
$(quick_add_item).text('View cart')
}
})
}
})
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment