Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #777859

    Hello, I’m trying to achieve something similar to this thread. Instead of getting the cart total, I was wondering if I could instead have the total amount of items in the cart? Similar to how the cart looks inherently.

    Here is a very small image of what I mean… So basically instead of an icon, it would say CART and then have the quantity of items in the cart next to it. Just like how enfold naturally shows it. The only difference is that I want mine to display within the menu using a shortcode.

    http://testing.curlyhost.com/wp-content/uploads/2017/04/Cart-w-number-in-menu.jpg

    #778790

    Hey bitojoe,

    Please add following code to Functions.php file in Appearance > Editor

    function avia_cart_count(){
    global $woocommerce;
    $count = $woocommerce->cart->cart_contents_count;
    if ($count > 0) {
    $avia_count = sprintf(_n(' %d', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count);
    return $avia_count;
    }
    }
    add_shortcode( 'cart_count', 'avia_cart_count' );

    then go to Appearance > Menus and add following shortcode into Navigation label field of your cart menu item

    [cart_count]

    Best regards,
    Yigit

    #778828

    Thank you so much! How might I add a “/ ” before the cart count like in my image but only display it when there are actually items in the cart? I was imagining using a psuedo before class but there isn’t anything to use one with…

    #778879

    Hey!

    Please change the code to following one

    function avia_cart_count(){
    global $woocommerce;
    $count = $woocommerce->cart->cart_contents_count;
    if ($count > 0) {
    $avia_count = sprintf(_n(' %d', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count);
    return "<span class='counter'>/ ".$avia_count."</span>";
    }
    }
    add_shortcode( 'cart_count', 'avia_cart_count' );

    Best regards,
    Yigit

    #778961

    Thanks again Yigit! Works perfectly.

    #778975

    Hey!

    You are welcome!

    For your information, you can take a look at Enfold documentation here – http://kriesi.at/documentation/enfold/
    And if there are features that you wish Enfold had, you can request them and vote the requested ones here – https://kriesi.at/support/enfold-feature-requests/
    For any other questions or issues, feel free to post them here on the forum and we will gladly try to help you :)

    Best regards,
    Yigit

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘Woocommerce Cart Shortcode’ is closed to new replies.