Last active
January 23, 2018 17:40
-
-
Save arobbins/f6f6744b64647db7a9e817788b8dca5a to your computer and use it in GitHub Desktop.
Custom order data example - AJAX sender
This file contains hidden or 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
/* | |
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