• tota040963

    (@tota040963)


    Dear all,

    There is a large volume of automated requests directed at the WooCommerce endpoint ?wc-ajax=get_refreshed_fragments—an endpoint used by the “Legacy Mini-Cart” to automatically update the cart without requiring a page refresh. I have implemented rules in Cloudflare (covering WAF, Bot Protection, and Challenges). However, a complete block is difficult to achieve, as the requests originate from thousands of different IP addresses, and the cf_clearance cookie allows verified visitors to proceed. A blanket block—which would stop all requests related to this issue—would also negatively impact legitimate users.

    The Legacy Mini-Cart will need to be replaced with the WooCommerce Mini-Cart Block—following a compatibility check with the current theme (YITH Proteo). The new Mini-Cart Block does not rely on the legacy Cart Fragments API, which allows us to exclude that specific endpoint without affecting the cart.

    Please advise.

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • preciseexpressions

    (@preciseexpressions)

    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:

    1. 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.

    1. 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 );

    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!

Viewing 1 replies (of 1 total)

You must be logged in to reply to this topic.