Trouble with time conditions

Hey gang. I’m likely missing something silly here.

See this setup:

As of the time of writing, the site is outputting the current time as 15:42, so that element should be displaying. But it’s not.

What am I missing?

Hey @foliot,

probably a local vs. server time issue. Try to create a small helper function in your child theme’s functions.php file or in a code snippet plugin of your choice to determine if it’s happy hour right now. This function could look like this:

function is_happy_hour() {
    $start = '15:00:00';
    $end = '16:00:00';

    $current_time = wp_date( 'H:i:s');

    return $current_time >= $start && $current_time <= $end;
}

Your condition could then look like this:

CleanShot 2023-05-24 at 16.02.02

Let me know if that helped.

Best,

André

1 Like

Hi @aslotta. This worked great! Thank you for the kind assistance and for taking the time to reply. I appreciate it.