• Resolved hnwp

    (@hnwp)


    It’s strange.

    Every time I add an item to the cart, the cart count fragments get updated (because of a custom function), but the “woocommerce_mini_cart()” does not.

    It seems I have to manually refresh the page.

    Also, removing an item from the cart does technically remove it, but the blockUI remains indefinitely, and requires a refresh.

    I’ve removed all plugins.
    I’ve checked my custom js.
    I’ve tweaked W3 Total Cache (and removed it).

    It seems like when I switched from using the widget cart shortcode shipped with woocommerce to just using the function woocommerce_mini_cart() has this issue continued (my guess).

    Any recommendations?

    • This topic was modified 6 years, 7 months ago by hnwp.

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Your custom add-to-cart Javascript will be calling an ajax function to do the add-to-cart, and this should include lines to regenerate the html for the mini cart contents:

    ob_start();
    woocommerce_mini_cart();
    $response->cart_content = ob_get_clean();

    Your Javascript ajax response function must update the cart div with this new content something like this:
    document.getElementsByClassName( "widget_shopping_cart_content" ).innerHTML = response.cart_content;

    Thread Starter hnwp

    (@hnwp)

    Hi Lorro.

    I don’t have any custom javascript ajax functions: they’re just the standard add to cart.

    Are you suggesting I hook something to the “added_to_cart” function?

    $(document.body).on("added_to_cart", function() { };?

    I’d have to ajax response to fill in there.

    I’m assuming woocommerce_mini_cart() doesn’t natively get updated upon adding to cart?

    • This reply was modified 6 years, 7 months ago by hnwp.

    The mini cart will be updated on a vanilla setup, but you mentioned in your first post you had a custom function to update the cart fragments. Its seems this is interfering with the usual behaviour.

    hi

    Thread Starter hnwp

    (@hnwp)

    The only thing “custom” is this, which just updates the cart count.

    //AJAX immediately update number of items in cart
    add_filter( 'add_to_cart_fragments', 'iconic_cart_count_fragments', 10, 1 );
    function iconic_cart_count_fragments( $fragments ) {
    
    	$fragments['span.cart-count'] = '<span class="cart-count">' . WC()->cart->get_cart_contents_count() . '</span>';
        	return $fragments;	
    }

    Even after commenting this out in my functions.php, the issue still persists.

    Thread Starter hnwp

    (@hnwp)

    Found the issue. Silly me.

    I removed the class “widget_shopping_cart_content”, which is what Woocommerce’s js was looking for to remove the blockUI and such.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Woocommerce_mini_cart Add to Cart ISsue’ is closed to new replies.