Daniel Posted August 11, 2015 Share Posted August 11, 2015 Hey Does anyone know how to add a menu item based on an active service? For example in V5 we could use: {if $clientsstats.productsnumactivereseller >= "1" or $clientsstats.productsnumactiveservers >= "1"} However I have no idea how to do this using the new hooks method. Any ideas? Thanks 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted August 11, 2015 Share Posted August 11, 2015 you would need to query database to check if logged-in use has any active products/services, then display whatever you need. $_SESSION['uid'] this variable contain logged-in user id, use to with your query 0 Quote Link to comment Share on other sites More sharing options...
Daniel Posted August 11, 2015 Author Share Posted August 11, 2015 That sucks, seems this was much simpler before I don't suppose anyone has the code for this handy? 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted August 11, 2015 Share Posted August 11, 2015 is that simple enough? <?php use WHMCS\View\Menu\Item as MenuItem; add_hook("ClientAreaPrimaryNavbar", 1, function (MenuItem $primaryNavbar){ # Add Admin Username $adminuser = "admin"; # When Client Logged-in if (isset($_SESSION['uid']) && $_SESSION['uid']!='0'){ $results = localAPI("getclientsproducts", array("clientid" => $_SESSION['uid']), $adminuser); $activeProducts = false; foreach ($results['products']['product'] as $product){ if ($product['status']=="Active"){ $activeProducts = true; } } # Client has active Products if ($activeProducts===true){ $primaryNavbar->addChild('MenuName') ->setLabel('New Menu Item') ->setUri('https://www.example.com/') ->setOrder(70); } } }); 0 Quote Link to comment Share on other sites More sharing options...
Daniel Posted August 11, 2015 Author Share Posted August 11, 2015 It looks like that just displays the item if they have an active service unless I've misunderstood? I need it to only display if they have an active server or reseller, i.e not if they have a shared account or other service. 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted August 11, 2015 Share Posted August 11, 2015 the following hook will add new menu item if the logged-in client has active service "server or reseller account", you only need to adjust your menu options (Label, URL, etc) <?php use WHMCS\View\Menu\Item as MenuItem; use Illuminate\Database\Capsule\Manager as Capsule; add_hook("ClientAreaPrimaryNavbar", 1, function (MenuItem $primaryNavbar){ $_SESSION['uid'] = intval($_SESSION['uid']); # When Client Logged-in if ($_SESSION['uid']!='0'){ $services = Capsule::table('tblhosting') ->where('tblhosting.userid', $_SESSION['uid']) ->where('tblhosting.status', 'Active') ->join('tblproducts', 'tblhosting.packageid', '=', 'tblproducts.id') ->get(); $activeProducts = false; foreach ($services as $service){ if (in_array($service->type, array("reselleraccount", "server"))){ $activeProducts = true; } } if ($activeProducts===true){ # Change Your Menu Settings Here $primaryNavbar->addChild('MenuName') ->setLabel('New Menu Item') ->setUri('https://www.example.com/') ->setOrder(70); } } }); 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted August 13, 2015 Share Posted August 13, 2015 just found a typo in my hook code, "domainstatus" instead of "status" <?php use WHMCS\View\Menu\Item as MenuItem; use Illuminate\Database\Capsule\Manager as Capsule; add_hook("ClientAreaPrimaryNavbar", 1, function (MenuItem $primaryNavbar){ $_SESSION['uid'] = intval($_SESSION['uid']); # When Client Logged-in if ($_SESSION['uid']!='0'){ $services = Capsule::table('tblhosting') ->where('tblhosting.userid', $_SESSION['uid']) ->where('tblhosting.domainstatus', 'Active') ->join('tblproducts', 'tblhosting.packageid', '=', 'tblproducts.id') ->get(); $activeProducts = false; foreach ($services as $service){ if (in_array($service->type, array("reselleraccount", "server"))){ $activeProducts = true; } } if ($activeProducts===true){ # Change Your Menu Settings $primaryNavbar->addChild('MenuName') ->setLabel('New Menu Item') ->setUri('https://www.example.com/') ->setOrder(70); } } }); ?> 0 Quote Link to comment Share on other sites More sharing options...
Daniel Posted August 13, 2015 Author Share Posted August 13, 2015 Thanks, while it seems to add the menu item it also results in "An Error Occured" in the checkout and prevents customers processing orders. It's a bit strange and I can't see any reason why it would do that 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.