Speed up Woocommerce WordPress

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/

Write a Comment

Comment

    • Hi Karim, one of the dequeue lines above does that as well.
      See “wp_dequeue_script( ‘wc-cart-fragments’ );”
      With this, cart fragments are no longer called outside shopping cart/cart/product page.

Webmentions

  • sans ordonnance kamagra sans ordonnance en ligne 2017-10-18

    kamagra de la pharmacie canadienne

    moins cher canada kamagra vente par correspondance

  • kamagra fedex doručení 2017-10-18

    kamagra z kanady

    opravdu kamagra funguje

  • how to order itraconazole cheap from usa 2017-10-18

    order itraconazole uk buy online

    online order itraconazole where to purchase

  • order fildena uk delivery 2017-10-18

    online order fildena canada over the counter

    discount fildena generic free shipping

  • cheap gabapentin price generic 2017-10-18

    get gabapentin generic uk buy

    buying gabapentin generic where to buy

  • purchase flexeril cyclobenzaprine uk buy online 2017-10-18

    ordering flexeril cyclobenzaprine price at walmart

    online order flexeril cyclobenzaprine cheap canadian pharmacy

  • order dutasteride generic new zealand 2017-10-18

    online order dutasteride generic is it legal

    buy cheap dutasteride uk where buy

  • get avodart uk cheap purchase buy 2017-10-18

    discount avodart purchase line

    buying avodart buy mastercard

  • cheap xifaxan generic available in united states 2017-10-18

    purchase xifaxan generic lowest price

    discount xifaxan cheap genuine

  • buy rifaximin cheap uk buy purchase 2017-10-18

    purchase rifaximin usa cheap

    buy cheap rifaximin cost tablet

  • ordering androxal no prescription overnight delivery 2017-10-18

    androxal australia cost

    online order androxal buy generic