Add following few lines into functions.php ( in your theme directory ), at the very bottom.
add_action( 'wp_enqueue_scripts', 'remove_woocommerce_when_not_needed', 99 ); function remove_woocommerce_when_not_needed() { remove_action( 'wp_head', array( $GLOBALS['woocommerce'], 'generator' ) ); if ( function_exists( 'is_woocommerce' ) ) { if ( ! is_woocommerce() && ! is_cart() && ! is_checkout() ) { // dequeue styles wp_dequeue_style( 'woocommerce_frontend_styles' ); wp_dequeue_style( 'woocommerce_fancybox_styles' ); wp_dequeue_style( 'woocommerce_chosen_styles' ); wp_dequeue_style( 'woocommerce-general' ); wp_dequeue_style( 'woocommerce-layout' ); wp_dequeue_style( 'woocommerce-smallscreen' ); wp_dequeue_style( 'sv-wc-payment-gateway-payment-form' ); // dequeue scripts wp_dequeue_script( 'wc_price_slider' ); wp_dequeue_script( 'wc-single-product' ); wp_dequeue_script( 'wc-add-to-cart' ); wp_dequeue_script( 'wc-cart-fragments' ); wp_dequeue_script( 'wc-checkout' ); wp_dequeue_script( 'wc-add-to-cart-variation' ); wp_dequeue_script( 'wc-single-product' ); wp_dequeue_script( 'wc-cart' ); wp_dequeue_script( 'wc-chosen' ); wp_dequeue_script( 'woocommerce' ); wp_dequeue_script( 'jquery-blockui' ); wp_dequeue_script( 'jquery-placeholder' ); wp_dequeue_script( 'fancybox' ); wp_dequeue_script( 'jqueryui' ); wp_dequeue_script( 'braintree-data' ); wp_dequeue_script( 'braintree-js' ); wp_dequeue_script( 'sv-wc-payment-gateway-payment-form'); } } }
Scripts checks if the page you are on actually needs woocommerce component ( e.g. product page, checkout page .. ) – if not, it will remove all scripts and styles related to Woocommerce and Braintree.
It’s also possible to disable woocommerce entirely on these pages through dedicated plugin – https://wordpress.org/plugins/plugin-organizer/
Also make sure you update maximum memory limit https://phpsolved.com/wordpress-adjust-maximum-memory-limit/