Jump to content

Display menu for one or more product groups


web2008

Recommended Posts

I have a menu/hook I want to display only for one or more product groups.Is there anyone who can help me with this?

function sitebuilder_hook_sidebar($sidebar) {
    $actions = $sidebar->getChild('Service Details Actions');
    if ($actions) {
        $actions->addChild('Sitebuilder', array(
            'name' => 'Sitebuilder',
            'label' => 'Sitebuilder',
            'uri' => 'index.php?m=sitebuilder',
            'order' => 999,
            'attributes' => array(
                'target' => '_blank'

 

Edited by WHMCS ChrisD
Placed code into a code box
Link to comment
Share on other sites

20 hours ago, web2008 said:

I have a menu/hook I want to display only for one or more product groups.Is there anyone who can help me with this?

try the following hook...

<?php

# Product Groups Sidebar
# Written by brian!

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimarySidebar', 1, function(MenuItem $primarySidebar)
{
	$service = Menu::context('service');    
	$groupID = $service->product->productGroupId;
	$validgroups = ['1','2','3'];

	if (!in_array($groupID,$validgroups)) {
		return;
	}

	if (!is_null($primarySidebar->getChild('Service Details Actions'))) {
            $primarySidebar->getChild('Service Details Actions')
				->addChild('Sitebuilder', array(
					'uri' => 'index.php?m=sitebuilder',
					'order' => 999,
					'attributes' => array(
						'target' => '_blank'
					)));
	}
});

jjZa6bj.png

I removed the name and label values from your hook because they were the same as the Child's name... and you only really need to add a label value if it's either a) different from the child's name or b) needs to use language strings. :idea:

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • 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