Created
January 27, 2015 02:57
-
-
Save siamkreative/75275b3d93671a54d02c to your computer and use it in GitHub Desktop.
EDD AJAX: Using Easy Digital Downloads with AJAX (on the Front-End)
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
$('.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