I created a hook to change the Template a client will see depending on which Client Group they are lumped into:-
<?php
function clientgroupTemplate($vars) {
$client = Menu::context('client');
$groupid = $client->groupid;
if ($groupid == 1) {
global $systpl;
$systpl = 'MY_TEMPLATE';
$GLOBALS['_SESSION']['Template'] = 'MY_TEMPLATE';
$GLOBALS['CONFIG']['Template'] = 'MY_TEMPLATE';
}
}
add_hook("ClientAreaPage", 1, "clientgroupTemplate");
However, the hook seem to only work on the second load, which means that the client will first see the default Template after login and only after a refresh or going to the second page will they see MY_TEMPLATE.
I tried disabling all other hooks to rule out any conflicts.
Is this due to caching like OPCache or is there a better way to write this hook?
Thank you.