Jump to content

Check email opt-in status for client


SteelSignature

Recommended Posts

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?

Link to comment
Share on other sites

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...

  1. 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.

  2. use models with the class docs...

    $client = Menu::context("client");
    $emailoptin = $client->marketingEmailsOptIn;

    ... should return true or false.

  3. 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.

  4. 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.

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