SteelSignature Posted December 5, 2019 Share Posted December 5, 2019 I'd like to run a check for email opt in on client nav/dashboard items. Easy to check on a .tpl template, but this seems to fail as a php hook. Any help would be appreciated. <?php use WHMCS\View\Menu\Item; add_hook('ClientAreaHomepagePanels', 1, function (Item $homePagePanels) { $emailoptin = boolval($_SESSION['marketing_emails_opt_in']); if ($emailoptin){ ... } }); I've come to realize that 'marketing_emails_opt_in' variable is only usable with certain hook functions; of which, there are none to check client details. Is there any way to do this? 0 Quote Link to comment Share on other sites More sharing options...
DennisHermannsen Posted December 6, 2019 Share Posted December 6, 2019 Maybe use GetClientsDetails? https://developers.whmcs.com/api-reference/getclientsdetails/ 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted December 6, 2019 Share Posted December 6, 2019 12 hours ago, SteelSignature said: I've come to realize that 'marketing_emails_opt_in' variable is only usable with certain hook functions; of which, there are none to check client details. Is there any way to do this? multiple ways - made easier by the fact that you know the client will be logged in - i'll use some email verification hooks as examples... query the database....ignore returning the array part as that won't be relevant for a homepage panels hook, but notice the two lines of code required to query the database to get this boolean value (0 or 1)... $client = Menu::context("client"); $emailoptin = Capsule::table('tblclients')->where('id',$client->id)->value('marketing_emails_opt_in'); remember to declare that you're using capsule too - otherwise, it won't work. use models with the class docs... $client = Menu::context("client"); $emailoptin = $client->marketingEmailsOptIn; ... should return true or false. the marketing value will exist inside the $clientsdetails array in the clientareahome template, which for most hooks you could access via $vars, but with HPP hooks, you could also access by declaring $smarty as a global - check out the first three lines of the hook below where i'm using variables from the template... generally, i'd only use this if you couldn't get the info easily from querying the database or the model - but it can be a useful quick solution when needed. you could use the API to get the value, e.g GetClientsDetails, but that would be supreme overkill if you only need one value from the returned array. once you have the value, then it can be used in your IF statements. 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.