jeffuk Posted November 14, 2017 Share Posted November 14, 2017 Is there a way to display a User Homepage Panel (custom hook) by user ID or product type? I can create the hook following the documentation but I am not sure how to display it by either assigning a user ID or product id. I only want to display it to certain users but I will use several different hooks as the content will be different to each customer. Hope that makes sense. Link to comment Share on other sites More sharing options...
jeffuk Posted November 14, 2017 Author Share Posted November 14, 2017 2 hours ago, jeffuk said: Is there a way to display a User Homepage Panel (custom hook) by user ID or product type? I can create the hook following the documentation but I am not sure how to display it by either assigning a user ID or product id. I only want to display it to certain users but I will use several different hooks as the content will be different to each customer. Hope that makes sense. This is what I mean: https://stackoverflow.com/questions/46266398/create-a-if-statement-in-whmcs I will give this a try using if (!is_null($service)) { if ($service['service']->packageId == 17) { return "something"; } else { return 'nothing'; } } return ''; Link to comment Share on other sites More sharing options...
brian! Posted November 15, 2017 Share Posted November 15, 2017 17 hours ago, jeffuk said: Is there a way to display a User Homepage Panel (custom hook) by user ID or product type? yes. 17 hours ago, jeffuk said: I can create the hook following the documentation but I am not sure how to display it by either assigning a user ID or product id. I only want to display it to certain users but I will use several different hooks as the content will be different to each customer. Hope that makes sense. I don't think it would make sense to use multiple hooks if a user is only going to see one panel... under those circumstances, i'd use one hook with multiple conditions - now if they are going to see multiple panels, then multiple hooks might be an option (even in the same file). for example, to create a panel that is only shown to specific clients on v7.4... <?php # HomePagePanel Hook # Written by brian! use WHMCS\View\Menu\Item; add_hook('ClientAreaHomepagePanels', 1, function(Item $homePagePanels) { $client = Menu::context('client'); $clientid = $client->id; $validids = [1,2,3,4]; if (in_array($clientid, $validids)) { $html = '<p>Congratulations '.$client->firstName.', you are a very special customer!</p>'; $homePagePanels->addChild('Jeff Demo Panel', array( 'label' => 'Demo Panel', 'icon' => 'fa-pie-chart', 'order' => 10, 'extras' => array( 'color' => 'blue', 'btn-link' => 'http://www.google.com', 'btn-text' => 'Google', 'btn-icon' => 'fa-google', ), 'bodyHtml' => $html, )); } }); the panel will only be shown to clients with IDs in the $validids array - any other user won't see the panel. doing the same by product ID is a little more involved - and there are multiple ways to do it... e.g, you could continue to use the Class docs (as I used in the above hook), you can query the database or even use the API. if we quickly query the database to see if the client has at least one specific products (i'm not currently checking if they're active products, but you could easily do that by adding another where statement to the query)... <?php # HomePagePanel Hook # Written by brian! use WHMCS\View\Menu\Item; use Illuminate\Database\Capsule\Manager as Capsule; add_hook('ClientAreaHomepagePanels', 1, function(Item $homePagePanels) { $client = Menu::context('client'); $validproducts = [48,123]; $myproducts = Capsule::table('tblhosting') ->where('userid',$client->id) ->whereIn('packageid',$validproducts) ->get(); if (count($myproducts)) { $html = '<p>Congratulations '.$client->firstName.', you have a valid qualifying product!</p>'; $homePagePanels->addChild('Jeff Demo Panel', array( 'label' => 'Demo Panel', 'icon' => 'fa-pie-chart', 'order' => 10, 'extras' => array( 'color' => 'blue', 'btn-link' => 'http://www.google.com', 'btn-text' => 'Google', 'btn-icon' => 'fa-google', ), 'bodyHtml' => $html, )); } }); if you wanted to do it on product types, then that would be a join to tblproducts, or tblproductgroups if you want to check the group the product is assigned to. with multiple {if} and/or {elseif} statements, you should be able to cover all eventualities in a single hook (if necessary). 1 Link to comment Share on other sites More sharing options...
jeffuk Posted November 15, 2017 Author Share Posted November 15, 2017 You are an absolute legend. Thank you so much, Brian It has taken me hours to come up with something that kind of worked but it's nowhere near as great a solution as to what you have provided. Link to comment Share on other sites More sharing options...
Recommended Posts