Tagged: 

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

    In the cart, how can I replace the subtotal with number of items in cart? Thanks in advance.

    #139992

    Hi,

    this is not easily possible because the ajax widget (provided by the woocommerce plugin) does not show a “total number of items” field and you’d need to write a custom function which extracts this information from the html code of the widget…

    #139993

    Sorry, I was not clear. I am talking about the cart dropdown that is persistent throughout the site (The one that is located in the navigation). When a customer adds an item to the cart, the subtotal is updated. Instead, I would like to show the number of items added to the cart. I tried replacing

    $cart_subtotal = $woocommerce->cart->get_cart_subtotal();

    with

    $cart_subtotal = $woocommerce->cart->get_cart_contents_count();

    in line 685 of config-woocommerce/config.php

    but that just flashes the number of items in the cart and then reverts back to the subtotal. Thanks.

    #139994

    Yes, but the answer is still the same. The reason is that our theme fetches the data from the ajax cart widget. This line

    $cart_subtotal = $woocommerce->cart->get_cart_subtotal();

    is only required to display the sub total value before the ajax cart data is loaded. As soon as the widget js code is ready our code triggers the ajax call to query the most recent data (= subtotal).

    However the ajax cart widget does not contain a “total number of items” field and we are not able to update the item count without rewriting the code.

    If you still want to show the items count you can deactivate the js/ajax function which updates the subtotal value (or in your case the item count) but imo this solution will irritate your customers because the item count won’t change when they add additional items to the cart. The user must first reload the page and afterwards your php code will update the item count. If you want to remove the “subtotal code” open up wp-contentthemesrepleteconfig-woocommercewoocommerce-mod.js and delete

    setTimeout(first_load_amount, 10);
    $('body').bind('added_to_cart', update_cart_dropdown);

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

The topic ‘Replace cart dollar amount with number of items’ is closed to new replies.