You can put this file into wp-content/mu-plugins folder.


See full details at https://gist.github.com/GeekPress/9d124b4694535454677fcebb2ee66b40


<?php
if ( isset( $_GET['wc-ajax'] ) &amp;amp;amp;&amp;amp;amp; 'get_refreshed_fragments' === $_GET['wc-ajax'] &amp;amp;amp;&amp;amp;amp; ( !isset( $_COOKIE['woocommerce_cart_hash'] ) || empty( $_COOKIE['woocommerce_cart_hash'] ) ) &amp;amp;amp;&amp;amp;amp; ( !isset( $_COOKIE['woocommerce_items_in_cart'] ) || empty( $_COOKIE['woocommerce_items_in_cart'] ) ) ) {
  $data = get_transient( 'rocket_get_refreshed_fragments_cache' );
  if ( ! empty( $data ) ) {
    $data = json_decode( $data );
    wp_send_json( $data );
  }
  ob_start();
  add_action( 'shutdown', function() {
    set_transient( 'rocket_get_refreshed_fragments_cache', ob_get_clean(), 7 * DAY_IN_SECONDS );
  }, 0 );
}
// Delete the transient when the current theme is changed.
add_action( 'switch_theme', function() {
  delete_transient( 'rocket_get_refreshed_fragments_cache' );
}, 0 );