A few years back I disabled the WooCommerce ajax call for refreshing the cart fragments on my homepage using this PHP function in my child theme’s functions.php:
/** Disable Ajax Call from WooCommerce */
add_action( 'wp_enqueue_scripts', 'dequeue_woocommerce_cart_fragments', 11);
function dequeue_woocommerce_cart_fragments() { if (is_front_page()) wp_dequeue_script('wc-cart-fragments'); }I notice it doesn’t seem to be working any longer as I’m seeing ?wc-ajax=get_refreshed_fragments in my browser dev tools when I load the homepage.
After Googling around I saw this blog post from last summer on the Woo Developer blog. So I tried using that function instead and was able to get it working. Is this now the recommended method?
While testing I found that the cart displayed in the header on the product page will update even when I disable the fragments refresh on all but the cart and checkout pages. This must mean that the theme (Flatsome) is handling this instead?
Any reason not to disable the WC fragments fresh everywhere but the cart and checkout? I tested logged in, logged out, viewed my account settings, etc., seems like there would be no reason to have the cart fragments running on most of the site.
My motivation here is mainly to streamline things so the site isn’t using so many server resources and also speed up page load times.
Thanks for any advice.
Oh, and if it helps anyone, here’s the function I’m currently testing:
// Disable Ajax Call from WooCommerce
add_filter( 'woocommerce_get_script_data', function( $script_data, $handle ) {
if ( 'wc-cart-fragments' === $handle ) {
if ( /*is_woocommerce() ||*/ is_cart() || is_checkout() ) {
return $script_data;
}
return null;
}
return $script_data;
}, 10, 2 );
The page I need help with: [log in to see the link]
