BrighteyesDesign
asked on
Hide content depending on the time.
Is it possible using php to display content depending on the time?
It's for a florist website. There's three options 'Delivery', 'same day delivery' and 'pick up'.
The function i'm after is for Sameday delivery, it's only available until 1pm so I want to remove that option after that time.
This obviously won't work but to show what I mean, something along the lines of......
<?php if past 1.pm ?>Sameday option <?php endif; ?>
It's for a florist website. There's three options 'Delivery', 'same day delivery' and 'pick up'.
The function i'm after is for Sameday delivery, it's only available until 1pm so I want to remove that option after that time.
This obviously won't work but to show what I mean, something along the lines of......
<?php if past 1.pm ?>Sameday option <?php endif; ?>
Your biggest problem is determining when it is 1PM at their shop. The time on your server will be the local time for the Server which isn't necessarily the same timezone as the shop. But the way to use the shop time is to set the timezone before you check the time. See here: http://php.net/manual/en/function.date-default-timezone-set.php
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Declare a function and give it a name such as "CheckTime()". This is written in JavaScript, so it should be easy enough to adjust it accordingly for the appropriate PHP syntax.
function CheckTime()
{
var bOK=true;
var dNow=GetDate();
if (dNow.getHour()>=13)
dNow=false;
return bOK;
}
Then in your PHP code (again, please forgive any syntactical errors) you would simply have:
<?php if CheckNowI() ?>Sameday option <?php endif; ?>