Skip to content

Instantly share code, notes, and snippets.

@siamkreative
Created January 27, 2015 02:57
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 siamkreative/75275b3d93671a54d02c to your computer and use it in GitHub Desktop.
Save siamkreative/75275b3d93671a54d02c to your computer and use it in GitHub Desktop.
EDD AJAX: Using Easy Digital Downloads with AJAX (on the Front-End)
$('.buy-now').on('click', function (event) {
event.preventDefault();
var el = $(this),
item_download = el.attr('data-id'),
current_page = el.attr('data-current'),
item_price_id = false;
$.ajax({
type: 'POST',
url: edd_scripts.ajaxurl,
data: {
action: 'my_action_add_to_cart',
download_id: item_download,
price_id: item_price_id,
current: current_page,
nonce: edd_scripts.ajax_nonce
},
beforeSend: function () {
el.addClass('loading');
},
success: function (response) {
// Remove the loading spinner
el.removeClass('loading');
// Open success message in Boostrap modal
$('#edd-success').modal('show');
// Replace "Buy Now" button with Checkout button
el.html('Checkout');
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment