PluginProbe
King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder / 51.1.87
King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder v51.1.87
51.1.87 51.1.86 51.1.84 51.1.85 51.1.83 51.1.82 51.1.81 51.1.79 51.1.78 51.1.77 51.1.76 51.1.74 51.1.75 51.1.65 51.1.64 51.1.63 trunk 51.1.14 51.1.2 51.1.35 51.1.36 51.1.37 51.1.38 51.1.39 51.1.44 All 41 releases
king-addons / includes / widgets / Woo_Shortcode_Cart / script.js

script.js in King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder 51.1.87, at includes/widgets/Woo_Shortcode_Cart/script.js

45 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Keep header/block mini-cart in sync after classic [woocommerce_cart] updates.
3 */
4 (function ($) {
5 'use strict';
6
7 let refreshing = false;
8
9 const refreshMiniCart = () => {
10 if (refreshing) {
11 return;
12 }
13 refreshing = true;
14
15 document.dispatchEvent(new CustomEvent('wc-blocks_added_to_cart', { bubbles: true }));
16 document.dispatchEvent(new CustomEvent('wc-blocks_removed_from_cart', { bubbles: true }));
17
18 if (window.wp && wp.data && wp.data.dispatch) {
19 try {
20 const cartStore = wp.data.dispatch('wc/store/cart');
21 if (cartStore && typeof cartStore.invalidateResolution === 'function') {
22 cartStore.invalidateResolution('getCartData');
23 }
24 } catch (e) {
25 // Store may be unavailable on pages without WooCommerce blocks.
26 }
27 }
28
29 if ($ && $.fn) {
30 $(document.body).trigger('wc_fragment_refresh');
31 }
32
33 window.setTimeout(() => {
34 refreshing = false;
35 }, 250);
36 };
37
38 if ($ && $.fn) {
39 $(document.body).on('updated_wc_div updated_cart_totals', refreshMiniCart);
40 } else {
41 document.body.addEventListener('updated_wc_div', refreshMiniCart);
42 document.body.addEventListener('updated_cart_totals', refreshMiniCart);
43 }
44 })(window.jQuery);
45