WordPress.org

Ready to get started?Download WordPress

Forums

WooCommerce Cart Total (10 posts)

  1. croberts1
    Member
    Posted 2 years ago #

    I recently installed WooCommerce on a WP site I manage. The plugin works wonders. However, I do have one small annoyance. The cart does not display the total number of items. I've searched around and found a solution on Github although I'm not sure how to implement it.

    Any help would be greatly appreciated.

    Github solution: https://gist.github.com/1730046

    Reference image: http://i42.tinypic.com/jabdoi.jpg

    Thanks!

  2. toumi
    Member
    Posted 1 year ago #

    I got here from google, and found your link ( THANK YOU )

    in case you didn't get it to work, or anyone came from google, here is how :

    you have to declar this first : <?php global $woocommerce; ?> //required !!!!

    And then put this wherever you want the total number of items to appear :

    <?php echo sprintf(_n('%d item', '%d items', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count);?>

    if someone want to print the total ( $ ) like me you can put this code :

    <?php echo $woocommerce->cart->get_cart_total(); ?>

    and here is the cart url too :
    <?php echo $woocommerce->cart->get_cart_url(); ?>

    So play with this as you see fit , any questions please do ask :)

    Thank you again croberts1

  3. rheos
    Member
    Posted 1 year ago #

    and where did you declare this global variable,btw ?

  4. rheos
    Member
    Posted 1 year ago #

    I'm trying to make the cart a main menu item (up next to login) and stick the number of items in the cart in there.

  5. toumi
    Member
    Posted 1 year ago #

    you declare it where ever you want, just make sure it's first before any code that depends on it... i.e : <?php echo sprintf(_n('%d item', '%d items', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count);?>

  6. rheos
    Member
    Posted 1 year ago #

    Ah yes. The issue I am having is we have put "cart" as a menu item in the top sitenav menu in the "whitelight commerce" theme.

    How could I get the cart item count in that menu.. It's not so easily accessible. is a javascript update going to be the easiest way to get it in there?

  7. toumi
    Member
    Posted 1 year ago #

    I suggest you don't put Cart with wordpress menu, you put the native menu items, and code the menu item "cart" after that...

  8. rheos
    Member
    Posted 1 year ago #

    I have been given a pretty specific design spec from my client. If there is some way to get it in there I'd like to do it. Would perhaps a small custom plug-in handle it or something like that?

    Right now the menu is.. "My Account Cart Checkout Logout"

    I just want to make it so that the it reads:

    "My Account Cart (3 items) Checkout Logout"

    Possible?

  9. rheos
    Member
    Posted 1 year ago #

    It seems what I might need is a "custom walker" going to see what I can discover about creating something like this..

  10. rheos
    Member
    Posted 1 year ago #

    after alot of research learning about how wordpress builds its menus I came up with an extension to the walker class that goes like this:

    http://pastebin.com/maQ2Xnjg

    works like a charm

Topic Closed

This topic has been closed to new replies.

About this Topic