Skip to content

Commit 6016112

Browse files
authored
Update hooks.php
1 parent 6b6c41e commit 6016112

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

chatwoot/hooks.php

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
/***************************************************************************
44
// * *
5-
// * Chatwoot WHMCS Addon (v1.1). *
5+
// * Chatwoot WHMCS Addon (v1.2). *
66
// * This addon modules enables you integrate Chatwoot with your WHMCS *
77
// and leverage its powerful features. *
88
// * Tested on WHMCS Version: 7.9.2 (7.9.2-release.1). *
@@ -79,35 +79,41 @@ function hook_chatwoot_footer_output($vars) {
7979
if (!is_null($client)){
8080
$chatwoot_output = "$chatwoot_jscode
8181
<script>
82-
window.onload = (event) => {
82+
window.addEventListener('chatwoot:ready', function () {
8383
window.\$chatwoot.setUser('$clientid', {
8484
email: '$clientemail',
8585
name: '$clientname',
8686
avatar_url: '$gravatarurl',
87-
})
87+
});
88+
8889
window.\$chatwoot.setLabel('$chatwoot_label')
89-
}
90-
window.chatwootSettings = {
91-
position: '$chatwoot_position',
92-
locale: '$chatwoot_lang',
93-
}
90+
91+
window.chatwootSettings = {
92+
position: '$chatwoot_position',
93+
locale: '$chatwoot_lang',
94+
}
95+
});
9496
</script>
9597
";
96-
} else {
98+
}
99+
else {
97100
$chatwoot_output = "$chatwoot_jscode
98101
<script>
99-
window.onload = (event) => {
102+
window.addEventListener('chatwoot:ready', function () {
100103
window.\$chatwoot.setLabel('$chatwoot_label')
101-
}
102-
window.chatwootSettings = {
103-
position: '$chatwoot_position',
104-
locale: '$chatwoot_lang',
105-
}
104+
105+
window.chatwootSettings = {
106+
position: '$chatwoot_position',
107+
locale: '$chatwoot_lang',
108+
};
109+
});
106110
</script>
107111
";
108-
}
109-
110-
echo $chatwoot_output;
112+
}
113+
114+
115+
// Now print JS code
116+
echo $chatwoot_output;
111117
}
112118

113119

@@ -118,10 +124,8 @@ function hook_chatwoot_logout_footer_output($vars) {
118124
});
119125
</script>
120126
";
121-
122127
echo $chatwoot_logoutJS;
123128
}
124129

125130
add_hook('ClientAreaFooterOutput', 1, 'hook_chatwoot_footer_output');
126-
127131
add_hook('ClientLogout', 1, 'hook_chatwoot_logout_footer_output');

0 commit comments

Comments
 (0)