Jump to content

Menu item based on active service


Daniel

Recommended Posts

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

Link to comment
Share on other sites

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

       }

   }


});

Link to comment
Share on other sites

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

       }

   }


});

Link to comment
Share on other sites

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

       }

   }


});

?>

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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • 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