WooCommerce Add to Cart does not automatically display in cart

This topic has 6 replies, 3 voices, and was last updated 9 years, 11 months ago ago by Olga Barlow

  • Avatar: t4c
    t4c
    Participant
    December 9, 2014 at 21:03

    Hello,

    I have all plugins up 2 date but if I add products to the cart (see here: http://www.turboforcar.de/shop/) the cart is not automatically updated with AJAX. Nothing happens. I have to manually refresh the page, then there is something in the cart – the price in the right corner is refreshed without reloading the page.

    I added the following to fix the Add to Cart function (fix from support):

    I’m using Leganda 2.4

    add_action('wp_ajax_et_woocommerce_add_to_cart', 'et_woocommerce_add_to_cart');
    add_action('wp_ajax_nopriv_et_woocommerce_add_to_cart', 'et_woocommerce_add_to_cart');
    
    if(!function_exists('et_woocommerce_add_to_cart')) {
    	function et_woocommerce_add_to_cart() {
    		ob_start();
    
    		$product_id        = apply_filters( 'woocommerce_add_to_cart_product_id', absint( $_POST['product_id'] ) );
    		$quantity          = empty( $_POST['quantity'] ) ? 1 : apply_filters( 'woocommerce_stock_amount', $_POST['quantity'] );
    		$passed_validation = apply_filters( 'woocommerce_add_to_cart_validation', true, $product_id, $quantity );
    
    		if ( $passed_validation && WC()->cart->add_to_cart( $product_id, $quantity ) ) {
    
    			do_action( 'woocommerce_ajax_added_to_cart', $product_id );
    
    			if ( get_option( 'woocommerce_cart_redirect_after_add' ) == 'yes' ) {
    				woocommerce_add_to_cart_message( $product_id );
    				$woocommerce->set_messages();
    			}
    
    			// Return fragments
    			et_woocommerce_get_refreshed_fragments();
    
    		} else {
    
    			header( 'Content-Type: application/json; charset=utf-8' );
    
    			// If there was an error adding to the cart, redirect to the product page to show any errors
    			$data = array(
    				'error' => true,
    				'product_url' => apply_filters( 'woocommerce_cart_redirect_after_error', get_permalink( $product_id ), $product_id )
    			);
    
    			$woocommerce->set_messages();
    
    			echo json_encode( $data );
    		}
    
    		die();
    	}	
    }
    5 Answers
    Avatar: Eva
    Eva Kemp
    Support staff
    December 10, 2014 at 10:38

    Hello,

    Please update the theme to the latest version 2.4.1.
    Some bugs are fixed there.

    Thank you.
    Regards,
    Eva Kemp.

    Avatar: t4c
    t4c
    Participant
    December 10, 2014 at 13:56

    Hi Eva,

    i downloaded the newest version on themeforest (http://themeforest.net/downloads -> legenda). style.css says 2.4.1. Still no product in cart, but what i’ve noticed so far: the cart is shown on the left side, if i click on the add to cart button (but it’s empty).

    Avatar: Eva
    Eva Kemp
    Support staff
    December 10, 2014 at 16:42

    Hello,

    I’ve checked your site and the Cart page isn’t empty. Products are displayed there.
    Also the cart is shown in sidebar because you might have added Woocommerce Cart widget into Shop sidebar in Appearance > Widgets.
    Please provide us with FTP and wp-admin panel credentials in Private Content and clarify how we can replicate the issue.

    Thank you.
    Regards,
    Eva Kemp.

    Avatar: t4c
    t4c
    Participant
    December 10, 2014 at 23:30

    See private content below.

    Please, contact administrator
    for this information.
    Avatar: Olga Barlow
    Olga Barlow
    Support staff
    December 11, 2014 at 09:53

    Hello,

    We are sorry, but if you want to use cart widget in sidebar you need to disable Ajax Filter (Theme Options > Shop > Enable Ajax Filter > Off). WooCommerce Cart widget requires page refreshing and does not work with Ajax.

    Regards,
    Olga Barlow

  • Viewing 6 results - 1 through 6 (of 6 total)

The issue related to '‘WooCommerce Add to Cart does not automatically display in cart’' has been successfully resolved, and the topic is now closed for further responses

8theme customization service
We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.