Jump to content

Need help with a hook to remove Product addons from categories.


RandomGuy

Recommended Posts

Hello, I'm trying to remove the product addons in the categories in whmcs. 

 

 edit.png.dbf8255ae67f16a0dd61e2a5fc0a793b.png

I have tired the following hook. But it didn't work.

 

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

   if (!is_null($primarySidebar->getChild('Categories'))) { 
       $primarySidebar->getChild('Categories')->removeChild('Product Addons'); 
   } 
});

 

What is that I'm missing?

Link to comment
Share on other sites

Quote

It is in the secondary-sidebar -- Then Categories - Then just Addons if I dont remember wrong.

Not in primary. you figer this out if you view the source code of your webpage and look at the element ID

Thank you ptomter.

This time it worked. Thanks for the suggestion to view the source code.

I have initially tried doing it with both Primary and secondary sidebars. 

The main problem in removing "Product adddons" is, I have been trying to remove the child "Product addons". This time I tried naming it just "Addons" and it worked.

 

The following code worked fine in removing "Product Addons"

 

add_hook('ClientAreaSecondarySidebar', 1, function (MenuItem $secondarySidebar)

   if (!is_null($secondarySidebar->getChild('Categories'))) { 
       $secondarySidebar->getChild('Categories')->removeChild('Addons'); 
   } 
});

Thanks again.

Link to comment
Share on other sites

3 hours ago, RandomGuy said:

The main problem in removing "Product adddons" is, I have been trying to remove the child "Product addons". This time I tried naming it just "Addons" and it worked.

when you're checking the source code, you need to see what the menuitemname value is - whatever that is, that's what you need to use in removeChild.

Link to comment
Share on other sites

  • 1 year later...

When i added that code it broke my website. I get this error

TypeError: Argument 1 passed to WHMCS\Utility\SafeInclude::{closure}() must be an instance of MenuItem, instance of WHMCS\View\Menu\Item given in /var/www/billing/includes/hooks/removeaddon.php:11
Stack trace:
#0 /var/www/billing/includes/hookfunctions.php(0): WHMCS\Utility\SafeInclude::{closure}(Object(WHMCS\View\Menu\Item))
#1 /var/www/billing/vendor/whmcs/whmcs-foundation/lib/ClientArea.php(0): run_hook('ClientAreaSecon...', Array, true)
#2 /var/www/billing/vendor/whmcs/whmcs-foundation/lib/ClientArea.php(0): WHMCS\ClientArea->outputWithoutExit()
#3 /var/www/billing/vendor/whmcs/whmcs-foundation/lib/Http/Message/AbstractViewableResponse.php(0): WHMCS\ClientArea->getOutputContent()
#4 /var/www/billing/vendor/zendframework/zend-diactoros/src/Response/SapiEmitterTrait.php(27): WHMCS\Http\Message\AbstractViewableResponse->getBody()
#5 /var/www/billing/vendor/zendframework/zend-diactoros/src/Response/SapiEmitter.php(34): Zend\Diactoros\Response\SapiEmitter->injectContentLength(Object(WHMCS\ClientArea))
#6 /var/www/billing/clientarea.php(0): Zend\Diactoros\Response\SapiEmitter->emit(Object(WHMCS\ClientArea))
#7 {main}

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