<?php
/**
 * Plugin Name: Disable WooCommerce Cart Fragments
 * Description: Disables WooCommerce cart fragments to improve site performance.
 * Version: 1.0
 * Author: Pantheon Professional Services
 */

// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

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

function dcf_disable_cart_fragments() {
    // Check if WooCommerce is active
    if ( function_exists( 'is_woocommerce' ) ) {

	if ( ! is_cart() && ! is_checkout() ) {
		wp_dequeue_script( 'wc-cart-fragments' );
		wp_deregister_script( 'wc-cart-fragments' );
		remove_action( 'wp_ajax_get_refreshed_fragments', 'wc_ajax_get_refreshed_fragments' );
		remove_action( 'wp_ajax_nopriv_get_refreshed_fragments', 'wc_ajax_get_refreshed_fragments' );
	}
    }
}
