pablo-sg-pacheco
11/24/2017 - 6:04 PM

Update the whole wishlist every time an item is added or removed, considering the wishlist is always present in all pages

Update the whole wishlist every time an item is added or removed, considering the wishlist is always present in all pages

/**
* Update the whole wishlist every time an item is added or removed, considering the wishlist is always present in all pages
* Plugin: Wish list for WooCommerce
*/

jQuery(document).ready(function($){

	//Get your wish list element first (Replace it by your wish list css class)
	var wish_list_div = '.wish-list';

	//Every time an item is toggled (i.e added or removed)
	$("body").on('alg_wc_wl_toggle_wl_item', function (e) {

		//Call a ajax function that gets the wish list shortcode
		$.post(alg_wc_wl.ajaxurl, {action:alg_wc_wl_pro_get_wl_shortcode_ajax_action}, function (response) {

			// Replace your wish list content by the updated one that comes through ajax
			if (response.success) {
				wish_list_div.replaceWith($(response.data.shortcode));				
			}

		});

	});

});