Jump to content

Add a cart icon hook to the script?


Web Host Pro

Recommended Posts

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 by Infopro
Please Attach Images to Your Posts.
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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']));
});

Link to comment
Share on other sites

I set them up, and sentq finishes them off... nice work! :idea:

 

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);
   }
});

Link to comment
Share on other sites

  • 4 years later...

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

Link to comment
Share on other sites

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");
Link to comment
Share on other sites

  • 1 month later...

@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 by DennisHermannsen
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated