![Check out Enfold](https://kriesi.at/wp-content/themes/kriesi/images/banner-enfold.jpg)
-
AuthorPosts
-
April 14, 2017 at 3:54 pm #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
April 17, 2017 at 4:17 pm #778790Hey 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,
YigitApril 17, 2017 at 5:30 pm #778828Thank 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…
April 17, 2017 at 7:24 pm #778879Hey!
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,
YigitApril 17, 2017 at 9:40 pm #778961Thanks again Yigit! Works perfectly.
April 17, 2017 at 10:24 pm #778975Hey!
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 -
AuthorPosts
- The topic ‘Woocommerce Cart Shortcode’ is closed to new replies.