I've a quick question. I have a call button on my site, and if possible I'd like to have a different phone number with PHP at different times.
Between 9am - 5pm, I'd like our local office number and between 5pm - 9am the next day, I'd like our 24 hour number.
Here's the current specific code in the header. It's using a Wordpress theme to call the call option, and the idea is to overwrite that with hard data. And here's the website in question.
With help from Iscariot, I have this code so far, but it's not quite working - the time is now 11am and it should be showing my first number (02840...) but it's not? I've even tried 1am to 11pm, but it will not kick in the first number.
<span class="call-us-button">
<?php if($hour > 1 && $hour < 23){
echo '' . do_shortcode('[button link="tel:02840-631-245"]<span class="call-button-inner"><i class="call-us-icon"></i>CALL 02840 631 245</span>[/button]'); } else {
echo '' . do_shortcode('[button link="tel:0800-077-6704"]<span class="call-button-inner"><i class="call-us-icon"></i>CALL 0800 077 6704</span>[/button]'); }
?></span>
I'd really appreciate any advice or pointers if you have any!
Thanks in advance,
Phil
$hour = date('G', time());
if($hour > 8 && $hour < 18){
// Phone Number
echo '' . do_shortcode('[button link="' . get_prime_options('call_button_url') . '"]<span class="call-button-inner"><i class="call-us-icon"></i>' . get_prime_options('call_button_text') . '</span>[/button]');
} else {
// other number
echo '' . do_shortcode('[button link="' . get_prime_options('call_button_url') . '"]<span class="call-button-inner"><i class="call-us-icon"></i>' . get_prime_options('call_button_text') . '</span>[/button]');
}
However you need to note that the functions get_prime_options('call_button_url') needs to be changed to something else, and you need to go into that file and add the other number for it.
Could you just use the date function to get what you want - the G
will return the current time in 24 hour time without leading zeroes.
if(date('G')>=9 && date('G') <= 17)
{
// show normal phone Num
}
else
{
// show after hours phone Num
}