Home Forums WoodMart support forum Add to cart button is very slow to add to cart product

Add to cart button is very slow to add to cart product

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #315821

    manjudomainkop
    Participant

    Hello Team,
    Add to cart button is loading very slow. Its taking time to add to cart the product. its only rolling while adding the product.

    How can i resole it?

    Attachments:
    You must be logged in to view attached files.
    #315827

    Artem Temos
    Keymaster

    Hi,

    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.

    Kind Regards

    #315830

    manjudomainkop
    Participant

    Hello,
    could you please help me in this topic. where to put this code in wordpress.
    Thanks. Hope you will help me in that matter.

    #315852

    Artem Temos
    Keymaster

    Hi,

    You can edit the functions.php file of the child theme via Appearance -> Theme editor.
    And you can find the Custom JS field in Theme Settings -> Custom JS https://gyazo.com/c5be8d93972d6de8e2b24cb59df00454

    Kind Regards

Viewing 4 posts - 1 through 4 (of 4 total)