Skip to content
This repository was archived by the owner on Mar 17, 2022. It is now read-only.

Commit 89ef045

Browse files
committed
addresses #408 WooCommerce 3.6.x: cart fragment script updates for 3.6
merged in updates from 3.6.3 WooCommerce cart-fragments.js
1 parent 544ec17 commit 89ef045

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

public/js/Cart.js

+25-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Modified WooCommerce cart-fragments.js script to break HTML5 fragment caching.
99
* Useful when switching languages. Adds support new Cart page ajax.
1010
*
11-
* Updated in line with WooCommerce 3.5.3 cart-fragments.js,
11+
* Updated in line with WooCommerce 3.6.3 cart-fragments.js,
1212
* only difference is the additional Polylang lines... and these commments
1313
**/
1414

@@ -63,6 +63,10 @@ jQuery( function( $ ) {
6363
var $fragment_refresh = {
6464
url: wc_cart_fragments_params.wc_ajax_url.toString().replace( '%%endpoint%%', 'get_refreshed_fragments' ),
6565
type: 'POST',
66+
data: {
67+
time: new Date().getTime()
68+
},
69+
timeout: wc_cart_fragments_params.request_timeout,
6670
success: function( data ) {
6771
if ( data && data.fragments ) {
6872

@@ -81,6 +85,9 @@ jQuery( function( $ ) {
8185

8286
$( document.body ).trigger( 'wc_fragments_refreshed' );
8387
}
88+
},
89+
error: function() {
90+
$( document.body ).trigger( 'wc_fragments_ajax_error' );
8491
}
8592
};
8693

@@ -117,7 +124,9 @@ jQuery( function( $ ) {
117124

118125
// Refresh when storage changes in another tab
119126
$( window ).on( 'storage onstorage', function ( e ) {
120-
if ( cart_hash_key === e.originalEvent.key && localStorage.getItem( cart_hash_key ) !== sessionStorage.getItem( cart_hash_key ) ) {
127+
if (
128+
cart_hash_key === e.originalEvent.key && localStorage.getItem( cart_hash_key ) !== sessionStorage.getItem( cart_hash_key )
129+
) {
121130
refresh_cart_fragment();
122131
}
123132
});
@@ -203,4 +212,18 @@ jQuery( function( $ ) {
203212
$( document.body ).on( 'adding_to_cart', function() {
204213
$( '.hide_cart_widget_if_empty' ).closest( '.widget_shopping_cart' ).show();
205214
});
215+
216+
// Customiser support.
217+
var hasSelectiveRefresh = (
218+
'undefined' !== typeof wp &&
219+
wp.customize &&
220+
wp.customize.selectiveRefresh &&
221+
wp.customize.widgetsPreview &&
222+
wp.customize.widgetsPreview.WidgetPartial
223+
);
224+
if ( hasSelectiveRefresh ) {
225+
wp.customize.selectiveRefresh.bind( 'partial-content-rendered', function() {
226+
refresh_cart_fragment();
227+
} );
228+
}
206229
});

public/js/Cart.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)