Hello @tota040963,
This is a very common issue with the legacy get_refreshed_fragments script. Because it triggers full PHP execution and WooCommerce session lookups on every request, distributed bots can quickly choke server resources even behind Cloudflare.
While moving to the modern Mini-Cart Block is the right long-term move, you don’t need a blanket block to stop this right now. Here are three actionable ways to kill the bot traffic immediately without affecting legitimate shoppers:
- Block/Bypass requests that lack a WooCommerce cart cookie (Cloudflare WAF)
Legitimate shoppers who need cart fragment updates will almost always carry a WooCommerce session or cart cookie (woocommerce_items_in_cart). Scrapers and headless bots hitting ?wc-ajax=get_refreshed_fragments typically have clean sessions with no cart cookies at all.
In Cloudflare (Security > WAF > Custom Rules), you can create a rule:
Expression: (http.request.uri.query contains “wc-ajax=get_refreshed_fragments” and not http.cookie contains “woocommerce_items_in_cart”)
Action: Block (or Managed Challenge)
This allows shoppers who actually added items to their cart to refresh their mini-cart seamlessly, while challenging or dropping the thousands of bot requests with empty sessions.
- Intercept via PHP before the full session loads
If you prefer handling it at the application layer, you can add a lightweight hook to your child theme’s functions.php to exit early if get_refreshed_fragments is requested without cart data:
add_action( ‘init’, function() {
if ( isset( $_GET[‘wc-ajax’] ) && ‘get_refreshed_fragments’ === $_GET[‘wc-ajax’] ) {
// If there are no items in cart cookie, return empty fragments without booting heavy logic
if ( empty( $_COOKIE[‘woocommerce_items_in_cart’] ) ) {
wp_send_json( array( ‘fragments’ => array() ) );
exit;
}
}
}, 1 );
- Dequeue cart fragments on non-shop pages
If your theme only needs the mini-cart on specific pages, you can dequeue the script on standard blog posts and static pages:
add_action( ‘wp_enqueue_scripts’, function() {
if ( ! is_woocommerce() && ! is_cart() && ! is_checkout() ) {
wp_dequeue_script( ‘wc-cart-fragments’ );
}
}, 20 );
(Full disclosure: I am the developer behind Checkout Abuse Protection on WordPress.org. We deal heavily with application-layer WooCommerce bot mitigation, and stopping bots from abusing uncached AJAX endpoints like cart fragments and search queries is one of the quickest ways to reclaim your server’s CPU.)
Hope this helps you stabilize the server!