Jump to content

Altering client area sidebar for specific product group


irh

Recommended Posts

I need to alter the sidebar to remove login to cPanel/webmail links for specific product group.

 

I have implemented a custom hook as advised in the documentation, which does this unconditionally:

 

add_hook('ClientAreaPrimarySidebar', 1, function (MenuItem $primarySidebar) {
 $serviceDetails = $primarySidebar->getChild("Service Details Actions");
 if (empty($serviceDetails)) {
   return;
 }

 $service_ids = [33];

 $serviceDetailsChildren = $serviceDetails->getChildren();

 $keysToUnset = ['Change Password', 'Login to cPanel', 'Login to Webmail'];

 foreach($serviceDetailsChildren as $key => $service_details_child) {
   if (in_array($key, $keysToUnset)) {
     $serviceDetails->removeChild($key);
   }
 }
});

 

However, I cannot find a way to determine product/service (or even better - service group) based on the `id` query string.

 

Any help?

Link to comment
Share on other sites

there would be a few ways to get the product ID - one of which would be to use the Class documentation... so if we modified your hook to use that...

 

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimarySidebar', 1, function (MenuItem $primarySidebar) {

   $serviceDetails = $primarySidebar->getChild("Service Details Actions");

   if (empty($serviceDetails)) {
       return;
   }

   $service = Menu::context('service'); 
   $pid = $service->packageId;
   $gid = $service->product->productGroupId;

   if ($gid == '10') {

       $serviceDetailsChildren = $serviceDetails->getChildren();
       $keysToUnset = ['Change Password', 'Login to cPanel', 'Login to Webmail'];

       foreach($serviceDetailsChildren as $key => $service_details_child) {
           if (in_array($key, $keysToUnset)) {
               $serviceDetails->removeChild($key);
           }
       }
   }
});

that will then give you access to 2 variables - $pid and $gid - then it should just be a case of modifying the if statement to check for specific products or productgroups (or an array of them)...

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