Web Host Pro Posted November 27, 2015 Share Posted November 27, 2015 (edited) Hi, Just trying to get some insight on adding a shopping cart icon like on this image to the WHMCS main menu. blog.webhost.pro/wp-content/uploads/2015/11/cart.jpg I can add hooks, I just have no idea how to add a hook next to the menu "account" drop down link. I also am not sure how to add an icon with a number to show how many items are in the shopping cart. I am willing pay for help as well. Any insight will help me. Thanks so much for your time. Charles Edited November 27, 2015 by Infopro Please Attach Images to Your Posts. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted November 27, 2015 Share Posted November 27, 2015 Hi Charles, I can add hooks, I just have no idea how to add a hook next to the menu "account" drop down link. take a look at the hook in the thread below - that will add a view cart link next to the account dropdown. http://forum.whmcs.com/showthread.php?106111-Moving-View-Cart-amp-Choose-language-to-a-secondarySidebar-possible&p=436527#post436527 and if you wanted to add an icon, the code would be... <?php use WHMCS\View\Menu\Item as MenuItem; add_hook('ClientAreaSecondaryNavbar', 1, function (MenuItem $secondaryNavbar) { $secondaryNavbar->addChild('View Cart', array( 'label' => Lang::trans('viewcart'), 'uri' => 'cart.php?a=view', 'order' => '0', )) ->setIcon('fa-shopping-cart'); }); I also am not sure how to add an icon with a number to show how many items are in the shopping cart. if you wanted to add a number after the label, that's a badge... <?php use WHMCS\View\Menu\Item as MenuItem; add_hook('ClientAreaSecondaryNavbar', 1, function (MenuItem $secondaryNavbar) { $secondaryNavbar->addChild('View Cart', array( 'label' => '', 'uri' => 'cart.php?a=view', 'order' => '0', )) ->setIcon('fa-shopping-cart') ->setBadge('5'); }); the only part that's missing is getting the number of items in the shopping cart - in the above code, it's hard-coded as 5 - it's shown in the header template using {$cartitemcount}... I think you would need to get that Smarty variable in your hook - or find some other way to get the value. 0 Quote Link to comment Share on other sites More sharing options...
Web Host Pro Posted November 27, 2015 Author Share Posted November 27, 2015 Great, almost there and thanks so much. Just working on the item number with the badge. I see that this is what shows the number {$cartitemcount} Any idea how to add that to the hook? I tried to add it to where you added the number in the badge but it just shows the words and doesn't grab anything. Maybe a path with it or something to tell it to do a command instead of text? <?php use WHMCS\View\Menu\Item as MenuItem; add_hook('ClientAreaSecondaryNavbar', 1, function (MenuItem $secondaryNavbar) { $secondaryNavbar->addChild('View Cart', array( 'label' => '', 'uri' => 'cart.php?a=view', 'order' => '{$cartitemcount}', )) ->setIcon('fa-shopping-cart') ->setBadge('5'); }); -- Another theme I use for WHMCS does this and it works: <a href="cart.php?a=view" class="quick-nav"><i class="fa fa-shopping-cart"></i> <span class="hidden-xs">{$LANG.viewcart} <span class="badge">{$cartitemcount}</span></span></a> Just can't figure out how to translate this in a hook. 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted November 27, 2015 Share Posted November 27, 2015 not tested well (can be improved), but you can use something like this: ->setBadge(count($_SESSION['cart']['products'])) 0 Quote Link to comment Share on other sites More sharing options...
Web Host Pro Posted November 27, 2015 Author Share Posted November 27, 2015 Hmm I tried that but just got a 500 error, thanks though. I'm trying everything I can get my hands to try and make it work. The link is already very helful just would like to show the cart items. I think it helps when shopping. [h=1]Server error[/h] 500 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted November 27, 2015 Share Posted November 27, 2015 this should be the final result: <?php use WHMCS\View\Menu\Item as MenuItem; add_hook('ClientAreaSecondaryNavbar', 1, function (MenuItem $secondaryNavbar) { $secondaryNavbar->addChild('View Cart', array( 'label' => 'Cart ', 'uri' => 'cart.php?a=view', 'order' => '0', )) ->setIcon('fa-shopping-cart') ->setBadge(count($_SESSION['cart']['products'])); }); 0 Quote Link to comment Share on other sites More sharing options...
Web Host Pro Posted November 27, 2015 Author Share Posted November 27, 2015 Awesome, mission accomplished. Really helpful guys! 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted November 28, 2015 Share Posted November 28, 2015 I set them up, and sentq finishes them off... nice work! as sentq says, this can be improved because the figure it currently shows isn't accurate - it's only showing the number of products, and if you have a product that requires a domain, the header will show "2" in the cart, this hook will show "1"... or if you only have a domain, the hook will show "0" whilst the header shows "1"... to get around this, you just need to make a slight change to the code.. <?php use WHMCS\View\Menu\Item as MenuItem; add_hook('ClientAreaSecondaryNavbar', 1, function (MenuItem $secondaryNavbar) { $itemsincart = (count($_SESSION['cart']['products']) + count($_SESSION['cart']['domains'])); $secondaryNavbar->addChild('View Cart', array( 'label' => '', 'uri' => 'cart.php?a=view', 'order' => '0', )) ->setIcon('fa-shopping-cart') ->setBadge($itemsincart); }); this method also gives you the option to only show the cart icon link if there is something in the cart... <?php use WHMCS\View\Menu\Item as MenuItem; add_hook('ClientAreaSecondaryNavbar', 1, function (MenuItem $secondaryNavbar) { $itemsincart = (count($_SESSION['cart']['products']) + count($_SESSION['cart']['domains'])); if ($itemsincart > 0) { $secondaryNavbar->addChild('View Cart', array( 'label' => '', 'uri' => 'cart.php?a=view', 'order' => '0', )) ->setIcon('fa-shopping-cart') ->setBadge($itemsincart); } }); 0 Quote Link to comment Share on other sites More sharing options...
thianbrodie Posted May 20, 2020 Share Posted May 20, 2020 Hey guys, In WHMCS , thanks for this <a href="cart.php?a=view" class="quick-nav"><i class="fa fa-shopping-cart"></i> <span class="hidden-xs">{$LANG.viewcart} <span class="badge">{$cartitemcount}</span></span></a> {$cartitemcount} would anyone have a way, snippet or hook, which when cart has 0 nothing it it, hide the badge? Thian 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted May 20, 2020 Share Posted May 20, 2020 44 minutes ago, thianbrodie said: {$cartitemcount} would anyone have a way, snippet or hook, which when cart has 0 nothing it it, hide the badge? that's just a variation on a hook I posted a yesterday.... <?php function client_hide_view_cart_hook($vars) { if ($vars['cartitemcount'] == 0) { $head_return = "<style>li.primary-action {display: none !important;}</style>"; return $head_return; } } add_hook("ClientAreaHeaderOutput",1,"client_hide_view_cart_hook"); 1 Quote Link to comment Share on other sites More sharing options...
thianbrodie Posted May 20, 2020 Share Posted May 20, 2020 Perfect, Thank you again Brian! 0 Quote Link to comment Share on other sites More sharing options...
DennisHermannsen Posted July 9, 2020 Share Posted July 9, 2020 (edited) @brian! there's just one issue with how you're getting the amount of items in the cart - it also grabs any item that you're currently putting in the cart (on the confproduct page) before adding them to the cart. This can be done to get the correct amount: add_hook('ClientAreaSecondaryNavbar', 1, function(MenuItem $secondaryNavbar) { $orderfrm = new WHMCS\OrderForm(); $cartitemcount = $orderfrm->getNumItemsInCart(); $secondaryNavbar->addChild('View Cart', array( 'label' => '', 'uri' => 'cart.php?a=view', 'order' => '0' )) ->setIcon('fa-shopping-cart') ->setBadge($cartitemcount); }); Edited July 9, 2020 by DennisHermannsen 2 Quote Link to comment Share on other sites More sharing options...
brian! Posted July 9, 2020 Share Posted July 9, 2020 50 minutes ago, DennisHermannsen said: This can be done to get the correct amount aah - I was trying to avoid using internal functions, defined in encoded files, that we probably shouldn't really know about. 😎 0 Quote Link to comment Share on other sites More sharing options...
DennisHermannsen Posted July 9, 2020 Share Posted July 9, 2020 No no no, I totally came up with that on my own, I swear 😜 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted July 9, 2020 Share Posted July 9, 2020 1 minute ago, DennisHermannsen said: No no no, I totally came up with that on my own, I swear then I humbly apologise Dennis! 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.