businessdad icon

WooCommerce Cache Handler - 3rd party plugin example

businessdad | PRO | 06/17/16 03:45:58 PM UTC | 0 ⭐ | 928 👁️ | Never ⏰ | []
JavaScript |

980 B

|

None

|

0 👍

/

0 👎

// Build a list of the elements to update, with the data associated to each one
// The data could go in a custom "data" attribute, and could be used to represent
// how the element should be rendered (e.g. it could contain the parameters for
// a shortcode)
var elements_to_update = {};
$('#some_element').each(function() {
    var $elem = $(this);
    elements_to_update[$elem.attr('id')] = $elem.data('your_custom_data');
});
 
// Prepare the Ajax request to update the element
var ajax_url = 'some_ajax_url';
var ajax_args = {
    'action': 'epo_get_addons',
    'elements': elements_to_update
}
// Fetch the update elements via Ajax
$.post(ajax_url, ajax_args, function(response) {
    // Debug
    console.log(response);
    
    // Update the elements on the page
    var new_elements = response.product_addons;
    for(var element_id in new_elements) {
        var html = new_elements[element_id];
        $('#' + element_id).html(html);
    }
    
    // Trigger initialisation scripts (pseudo code)
    epo.init();
});

Comments