Skip to content

Instantly share code, notes, and snippets.

@arobbins
Last active January 23, 2018 17:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arobbins/f6f6744b64647db7a9e817788b8dca5a to your computer and use it in GitHub Desktop.
Save arobbins/f6f6744b64647db7a9e817788b8dca5a to your computer and use it in GitHub Desktop.
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