Display Bot During Business Hours Only (Livechat & Popup)

Abby Updated by Abby

In the case that we only want to display the bot during business hours, we'll simply add a snippet to the Javascript of the bot (only Livechat & Popup).

In this workaround we'll use the Javascript method Date to get the current time and compare it with our business hours. Keep in mind that this native Javascript method doesn't support timezones.

We'll copy the snippet below and paste it in the 'Design'>'Custom Code'>'Add Javascript' section of our bot:


<script>
/* remove slash and asterisk to apply this function, keep them to work on your bot outside of business hours



let myLandbot = this;
myLandbot.onLoad(function() {
var d = new Date();
var n = d.getDay();
var now = d.getHours() + "." + d.getMinutes();
var weekdays = [
["Sunday"],
["Monday", 8.00, 17.00],
["Tuesday", 8.00, 17.00],
["Wednesday", 8.00, 17.00],
["Thursday", 8.00, 17.00],
["Friday", 8.00, 17.00],
["Saturday"] // we are closed, sorry!
];
var day = weekdays[n];


if (now > day[1] && now < day[2] || now > day[3] && now < day[4]) {
console.log("We're open right now!");
}
else {
console.log("Sorry, we're closed!");
myLandbot.destroy();
}
})
</script>

The comment in the snippet is there so you can edit the bot outside of business hours, if you remove it outside of business hours, the bot won't appear, and you won't be able to edit it.

So once you're done editing the hours and the bot, just remove the following:

   /* remove slash and asterisk to apply this function, keep them to work on your bot outside of business hours

Here's where you can edit the hours:

  var weekdays = [
["Sunday"],
["Monday", 8.00, 17.00],
["Tuesday", 8.00, 17.00],
["Wednesday", 8.00, 17.00],
["Thursday", 8.00, 17.00],
["Friday", 8.00, 17.00],
["Saturday"] // we are closed, sorry!
];

If you have a break between opening times, you can add it like this:

var weekdays = [
["Sunday", 9.30, 12.00, 15.30,22.00],
["Monday", 8.30, 12.00, 15.30,19.00],
["Tuesday", 8.30, 12.00, 15.30,19.00],
["Wednesday", 8.30, 12.00, 15.30,19.00],
["Thursday", 8.30, 12.00, 15.30,19.00],
["Friday", 8.30, 11.30],
["Saturday"] // we are closed, sorry!
];

And that's it! If they open your webpage outside of business hours the bot won't appear.

How did we do?

Launch Bot On Exit Intent

Open / Close a Web bot (embedded)

Contact