Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Custom order data example - AJAX sender
/*
Step 1. Add an AJAX POST request to the add to cart click event.
Resolves through the then() method once the data has been saved. You'll need to
write some jQuery to fill in the "dynamicValues" object according to your own markup
*/
jQuery('.wps-add-to-cart').on('click', function(e) {
jQuery.ajax({
method: 'POST',
url: 'http://wpstest.test/wp/wp-admin/admin-ajax.php', // This needs to point to the admin-ajax.php file within your WordPress setup.
dataType: 'json',
data: {
action: 'save_dynamic_values_to_session',
dynamicValues: { // Dynamically grab this data according to your unique setup
dynamicValue1: 'Hello!',
dynamicValue2: 'Greetings!'
}
}
}).then(function(data) {
console.log('Data has been saved');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.