Skip to main content
FolksSpeakersPluginsThemesEventsSnippetsShippedCommunityResources
Login Join
Snippet · PHP

Disable WooCommerce Cart Fragments for Better Performance

Shared by Abdullah Kaludi · May 4, 2026 · @wp_enqueue_scripts

3 views
1 upvote
Back to Snippets

WooCommerce cart fragments can create unnecessary AJAX requests on pages where the cart is not needed. Disabling them can improve frontend performance and page speed.

add_action( 'wp_enqueue_scripts', 'disable_woocommerce_cart_fragments', 11 );

function disable_woocommerce_cart_fragments() {
    if ( is_front_page() || is_home() || is_page() || is_single() ) {
        wp_dequeue_script( 'wc-cart-fragments' );
    }
}