Home Forums WoodMart support forum Page loading speed is very slow – Example Add to cart function Reply To: Page loading speed is very slow – Example Add to cart function

#315746

Artem Temos
Keymaster

Try to add the following PHP code snippet to the child theme functions.php file to fix this

add_filter( 'woocommerce_add_to_cart_fragments', 'woodmart_cart_data', 30 );
function woodmart_cart_data( $array ) {
	ob_start();
	woodmart_cart_count();
	$count = ob_get_clean();

	ob_start();
	woodmart_cart_subtotal();
	$subtotal = ob_get_clean();

	$array['span.wd-cart-number_wd']   = $count;
	$array['span.wd-cart-subtotal_wd'] = $subtotal;

	return $array;
}

and put the following code to the Custom JS in Theme Settings

jQuery( document.body ).on( 'added_to_cart removed_from_cart', function( e, fragments ){
	if ( fragments ) {
			jQuery.each( fragments, function( key, value ) {
				jQuery( key.replace('_wd','') ).replaceWith( value );
			});

			jQuery( document.body ).trigger( 'wc_fragments_loaded' );
		}
});

Then clear your browser cache and check the add to cart speed.