Skip to content

Commit a2bc3c3

Browse files
committed
fix an issue where $client is null on some pages
1 parent 8f413ab commit a2bc3c3

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

chatwoot/hooks.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,25 +80,25 @@ function hook_chatwoot_output($vars)
8080
$user_browser = getBrowser();
8181

8282
# Fetch labels
83-
if (!is_null($client)) {
83+
if (!is_null($user)) {
8484
$chatwoot_label = $chatwoot_setlabelloggedin;
8585
}
8686

87-
# Get client ID and set chat ID
88-
if ($user && $user->isOwner(CurrentUser::client())) {
87+
# Get client ID and set contact ID
88+
if ($user && $client && $user->isOwner(CurrentUser::client())) {
8989
$ClientID = $client->id; //$vars['clientsdetails']['id'];
9090
} elseif ($user) {
9191
$ownedClients = $user->ownedClients()->all();
9292
$ClientID = $ownedClients[0]['id'];
9393
}
9494

95-
if (!is_null($client)) {
95+
if (!is_null($user)) {
9696
$ClientChatID = hash_hmac("sha256", $ClientID, $signing_hash);
9797
$identifier_hash = hash_hmac("sha256", $ClientChatID, $verification_hash);
9898
}
9999

100-
# getting Client Info
101-
if (!is_null($client)) {
100+
# build contact info
101+
if (!is_null($user)) {
102102

103103
$apiPostData = array('clientid' => $ClientID, 'stats' => true);
104104
$apiResults = localAPI('GetClientsDetails', $apiPostData);
@@ -142,7 +142,7 @@ function hook_chatwoot_output($vars)
142142

143143
# Now let's prepare our code for final output
144144

145-
if (!is_null($client)) {
145+
if (!is_null($user)) {
146146

147147
$chatwoot_output =
148148
"$chatwoot_jscode

0 commit comments

Comments
 (0)