Solved

Show different text/hide phone number based on time of day?

  • 5 January 2023
  • 5 replies
  • 51 views

Userlevel 1
Badge

Hello,

We are looking for the text(a phone number) to be removed after a certain time of day(8Pm) from our pages, so that people can only contact us via a form on the page. But I am not sure how to go about this, I searched and found this thread:
Switch Text Based On Time Of Day | Community (unbounce.com)
Where something similar is discussed, but I am rather lost by the code and am not sure where or how to even use it, plus it’s from 9 years ago.

Does anyone know how to achieve what we are after without creating a bunch of landing pages without the phone number and manually turning them, while turning the ones with the phone number off, at 8PM every day?

icon

Best answer by Oliver_Lord 6 January 2023, 17:51

View original

5 replies

Userlevel 3
Badge

Hey @Devam, thanks for posting! :)

I do have a non code solution that you could try! Have you thought about adding the phone number to your page via a Sticky bar instead? We have a Scheduling feature as part of our Advanced Targeting for Popups and Sticky bars available for our Accelerate and Concierge customers. You can Start/Stop showing a Sticky bar at a certain time and date:

 

 

You can read more about Advanced Targeting here. I hope this helps @Devam

Userlevel 4
Badge

Hi @Devam. Happy New Year to you!

 

Thanks for your post. I wasn’t aware of the ability to do this, so I appreciate you bringing this to our attention.

I took a look around, and I found the following thread in the Unbounce Community:

This one is much more recent, and the instructions seem far more clear and concise.

 

I hope this helps you to get your page looking how you want!

Userlevel 1
Badge

Hello everyone, I tried going with the javascript route as the sticky bar idea would make changes to the page that would make the landing pages look bad. So I was able to add the code, but it doesn’t seem to be working, am I making a mistake somewhere?

<script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>

<script>

$(document).ready(function(){

//give the offset of your city

var offset = -6;



// create Date object for current location

var d = new Date();

// convert to msec

// subtract local time zone offset

// get UTC time in msec

var utc = d.getTime() + (d.getTimezoneOffset() * 60000);



// create new Date object for different city

// using supplied offset

var nd = new Date(utc + (3600000*offset));



// return time as a string

// return "The local time for city"+ city +" is "+ nd.toLocaleString() + "and time is "+nd.toLocaleTimeString() + " hour is "+nd.getHours();

var hour = nd.getHours();



console.log(hour);

if (hour >= 17 || hour <= 9) {

$("#lp-pom-box-347").hide();

} else {

$("#lp-pom-button-453").show();

}

});



</script>

 

Userlevel 1
Badge

Hello everyone, I was able to figure it out. The button to be hid was just not the same in both lines of code. Thank you!

Userlevel 4
Badge

Hey @Devam,

 

Thanks for confirming. I’m happy to see that the script is working for you. Have a great day!

 

Best,

 

Olly 

Reply