functions.php
function add_olarkchat() {
$olarkcode = "1111-333-22-4444";
?>
<!-- begin olark code -->
<script data-cfasync="false" type='text/javascript'>/*<![CDATA[*/window.olark||(function(c){var f=window,d=document,l=f.location.protocol=="https:"?"https:":"http:",z=c.name,r="load";var nt=function(){
f[z]=function(){
(a.s=a.s||[]).push(arguments)};var a=f[z]._={
},q=c.methods.length;while(q--){(function(n){f[z][n]=function(){
f[z]("call",n,arguments)}})(c.methods[q])}a.l=c.loader;a.i=nt;a.p={
0:+new Date};a.P=function(u){
a.p[u]=new Date-a.p[0]};function s(){
a.P(r);f[z](r)}f.addEventListener?f.addEventListener(r,s,false):f.attachEvent("on"+r,s);var ld=function(){function p(hd){
hd="head";return["<",hd,"></",hd,"><",i,' onl' + 'oad="var d=',g,";d.getElementsByTagName('head')[0].",j,"(d.",h,"('script')).",k,"='",l,"//",a.l,"'",'"',"></",i,">"].join("")}var i="body",m=d[i];if(!m){
return setTimeout(ld,100)}a.P(1);var j="appendChild",h="createElement",k="src",n=d[h]("div"),v=n[j](d[h](z)),b=d[h]("iframe"),g="document",e="domain",o;n.style.display="none";m.insertBefore(n,m.firstChild).id=z;b.frameBorder="0";b.id=z+"-loader";if(/MSIE[ ]+6/.test(navigator.userAgent)){
b.src="javascript:false"}b.allowTransparency="true";v[j](b);try{
b.contentWindow[g].open()}catch(w){
c[e]=d[e];o="javascript:var d="+g+".open();d.domain='"+d.domain+"';";b[k]=o+"void(0);"}try{
var t=b.contentWindow[g];t.write(p());t.close()}catch(x){
b[k]=o+'d.write("'+p().replace(/"/g,String.fromCharCode(92)+'"')+'");d.close();'}a.P(2)};ld()};nt()})({
loader: "static.olark.com/jsclient/loader0.js",name:"olark",methods:["configure","extend","declare","identify"]});
/* custom configuration goes here (www.olark.com/documentation) */
olark.identify(<?php echo "'".$olarkcode."'"; ?>);/*]]>*/</script><noscript><a href="https://www.olark.com/site/<?php echo $olarkcode; ?>/contact" title="Contact us" target="_blank">Questions? Feedback?</a> powered by <a href="http://www.olark.com?welcome" title="Olark live chat software">Olark live chat software</a></noscript>
<!-- end olark code -->
<?php
echo '<script type="text/javascript">';
echo "olark('api.chat.onBeginConversation', function(){";
if ( is_user_logged_in() ) {
$curruser = wp_get_current_user();
echo "olark('api.visitor.updateEmailAddress', {emailAddress: '". $curruser->user_email ."'});";
echo "olark('api.visitor.updateFullName', {fullName: '". $curruser->user_firstname ." ". $curruser->user_lastname ."'});";
echo "olark('api.chat.sendNotificationToOperator', {body: '** Logged in: YES ** '});";
}else{
echo "olark('api.chat.sendNotificationToOperator', {body: '** Logged in: NO ** '});";
}
echo "});";
echo '</script>';
}
add_action('wp_footer', 'add_olarkchat', 10, 1);
This is fantastic Dean. Thank you so much. It’s exactly what I’ve been searching for this week while testing out Olark on my membership site (Woocommerce and Pmpro). In fact, I wrote a super long blog post yesterday about my search for the perfect live chat wp plugin 🙂
Thanks again!
Loralee
Hi Loralee, I’m happy it has helped you out.
I must agree with your post re Co-Browsing being your favorite feature however I does freak some users out (just a bit).