8
8
* Modified WooCommerce cart-fragments.js script to break HTML5 fragment caching.
9
9
* Useful when switching languages. Adds support new Cart page ajax.
10
10
*
11
- * Updated in line with WooCommerce 3.5 .3 cart-fragments.js,
11
+ * Updated in line with WooCommerce 3.6 .3 cart-fragments.js,
12
12
* only difference is the additional Polylang lines... and these commments
13
13
**/
14
14
@@ -63,6 +63,10 @@ jQuery( function( $ ) {
63
63
var $fragment_refresh = {
64
64
url : wc_cart_fragments_params . wc_ajax_url . toString ( ) . replace ( '%%endpoint%%' , 'get_refreshed_fragments' ) ,
65
65
type : 'POST' ,
66
+ data : {
67
+ time : new Date ( ) . getTime ( )
68
+ } ,
69
+ timeout : wc_cart_fragments_params . request_timeout ,
66
70
success : function ( data ) {
67
71
if ( data && data . fragments ) {
68
72
@@ -81,6 +85,9 @@ jQuery( function( $ ) {
81
85
82
86
$ ( document . body ) . trigger ( 'wc_fragments_refreshed' ) ;
83
87
}
88
+ } ,
89
+ error : function ( ) {
90
+ $ ( document . body ) . trigger ( 'wc_fragments_ajax_error' ) ;
84
91
}
85
92
} ;
86
93
@@ -117,7 +124,9 @@ jQuery( function( $ ) {
117
124
118
125
// Refresh when storage changes in another tab
119
126
$ ( 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
+ ) {
121
130
refresh_cart_fragment ( ) ;
122
131
}
123
132
} ) ;
@@ -203,4 +212,18 @@ jQuery( function( $ ) {
203
212
$ ( document . body ) . on ( 'adding_to_cart' , function ( ) {
204
213
$ ( '.hide_cart_widget_if_empty' ) . closest ( '.widget_shopping_cart' ) . show ( ) ;
205
214
} ) ;
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
+ }
206
229
} ) ;
0 commit comments