Advertisement
businessdad

WooCommerce Cache Handler - 3rd party plugin example

Jun 17th, 2016
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Build a list of the elements to update, with the data associated to each one
  2. // The data could go in a custom "data" attribute, and could be used to represent
  3. // how the element should be rendered (e.g. it could contain the parameters for
  4. // a shortcode)
  5. var elements_to_update = {};
  6. $('#some_element').each(function() {
  7.     var $elem = $(this);
  8.     elements_to_update[$elem.attr('id')] = $elem.data('your_custom_data');
  9. });
  10.  
  11. // Prepare the Ajax request to update the element
  12. var ajax_url = 'some_ajax_url';
  13. var ajax_args = {
  14.     'action': 'epo_get_addons',
  15.     'elements': elements_to_update
  16. }
  17. // Fetch the update elements via Ajax
  18. $.post(ajax_url, ajax_args, function(response) {
  19.     // Debug
  20.     console.log(response);
  21.    
  22.     // Update the elements on the page
  23.     var new_elements = response.product_addons;
  24.     for(var element_id in new_elements) {
  25.         var html = new_elements[element_id];
  26.         $('#' + element_id).html(html);
  27.     }
  28.    
  29.     // Trigger initialisation scripts (pseudo code)
  30.     epo.init();
  31. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement