How to render an element with mutiple conditions time & date?

Guys, I am stuck and need some help with conditions.
I want to render an element based on weekdays and time, so the element should render:

  1. Mo - Thu - before 08:00 and after 17:00
  2. Fridays from 12:00 to 23:59
  3. Saturdays and Sundays

What I got:

  1. Mo - Thu - before 08:00 and after 17:00 - this translates to:
    Weekday >= Monday AND Weekday <= Thursday AND Time <= 08:00 AND Time >= 17:00

  2. Friday - after 12:00 and before 23:59
    Weekdays == Friday AND time >=12:00 AND time <=23:59

  3. Saturday and Sunday
    Weekdays <=Saturday AND weekdays <= Sunday

When implementing these conditions individually on ‘duplicated’ elements, they all work fine. However, as soon as I try to combine them on 1 element with OR they fail to work.

What am I doing wrong here? Any help is appreciated.

Hi @cmgramse,

I think you should use AND :slight_smile:

HI @MartinWB - so you mean I should use AND between the individual sets of conditions like so:

  1. Mo - Thu - before 08:00 and after 17:00 - this translates to:
    Weekday >= Monday AND Weekday <= Thursday AND Time <= 08:00 AND Time >= 17:00

AND

  1. Friday - after 12:00 and before 23:59
    Weekdays == Friday AND time >=12:00 AND time <=23:59

AND

  1. Saturday and Sunday
    Weekdays <=Saturday AND weekdays <= Sunday

–if that’s the case how am I going to do that…? I thought the OR in between sets was a given…

If you click on the + at the top where it says “Conditions” to add a new Condition you get “OR” but if you click on the “+” at the bottom of the existing condition then it adds the next as an “AND”.

Not very intuitive and would be much better if you could just click on the AND/OR to toggle it.

1 Like

Sorry for late reply… Yes, use AND as @alanj explained… It should work as you expect :slight_smile:

Hi @alanj and @MartinWB - thanks for replying! After fiddling around with the conditions I realized that my first approach above did not work. It is quite difficult to test.

a) One thing I found out was that for time conditions, you need to check that the WordPress instance is actually running on the correct timezone - in my case AMSTERDAM did not really work, I had to use UTC+1.

EDIT: Right now I am uncertain that the WP time-settings are recognised in Bricks. When I use the UTC time my conditions work as expected, as soon as I enter ‘local’ (server) time - things do not respond correctly…

b) I had problems in defining conditions-sets that use 2 ‘in-between’ expressions such as:
(day>=Mo. AND day<=Th.) AND (time<=08:00 AND time>=17:00)
This did not really work as expected. Instead I had to use the following:
(day>=Mo. AND day<=Th. AND time<=08:00) OR (day>=Mo. AND day<=Th. AND time>=17:00)

I have attached an image of the complete conditional expression that I am currently testing.

As to your replies: In my opinion, you can only add ‘AND’ in a conditon-set through the “+” at the bottom of an existing condition. In-between condition sets you can only add an ‘OR’.

Thanks for the help.

So I have done some further testing. I have adjusted the conditions to the following:

  1. Day>=Monday AND Day<=Thursday AND Time<=07:00 AND Time>=16:00
    OR
  2. Day==Friday AND Time<11:00
    OR
  3. Day == Saturday
    OR
  4. Day == Sunday

Following observations:
a) Local time does not seem to be considered by BRICKS conditions. I have to use UTC time, then the time conditions work as intended.

b) Combining condition-set (1) with condition-set (2) as shown above will cause the element to be rendered ALWAYS at time of (2), irrespective of the ‘DAY’ condition. To me this seems to be a BUG - but I would really like someone else to confirm this!

So I’m running into a situation where I’m trying to display a phone number during 9-5 hours but then a button in the same location for after 5 on weekdays and all day on weekends.

I went through and tried the same conditions as your written explanation above and had zero luck. The phone number just displays all the time and the button never shows up. I’ve attached a screenshot of what I’ve tried. The call is the condition for the phone number and the shop plans button is the one for the after hours button. Any ideas what I’m doing wrong here?

Hey @RMBC803 -while I am not an expert in this myself, let’s see whether I can help you.

  1. telephone number visible between 9-5 // mo. - fr.
    For the phone number to be visible the condition we specify needs to be true. So I would start with:

Day >= mo AND day <= fr AND time >= 08:00
(last condition is where I differ from your setup) OR
Day >= mo AND day <= fr AND time <= 17:00

—you cannot simply take over my conditions, as I actually wanted to do the opposite (at least not for the phone number!) I wanted to show an element before 09:00 and after 17:00. Please bear in mind that I ran into problems with the server time and the it’s Interpretation by Bricks. So I had to use 08:00 instead of 09:00. Also for some reason - I could not get the Friday condition to work.

So I actually had to fallback on a solution where I rely on 2 banners:

  1. that shows between mo - th // before 08:00 and after 16:00 OR sat. OR Sun.
  2. that shows fr after 11:00

There is a ticket open - and it’s been worked on currently

Hope this helps you further

Just throwing this in…

Have you already seen this video from Grant Ambrose?

He is showing how to make the store open / store closed element.

Cheers

Patric

1 Like

Great stuff, @Patric !! Wasn’t aware of this channel, yet.
Using functions avoids the current problems with time and seems quite elegant. I think I get right into implementing this. :slight_smile:

Side note: That’s the most clickbaity thumbnail I’ve ever seen :rofl:

The saga continues…

His videos are also very very good.

Wow @Patric - that one is also quite good. Must say, from a maintenance perspective having all data collected in an options page is certainly way more handy. No fiddling about remembering a couple of months later where you stuffed the info…

For my part I am at the moment happy with the solution I have got…but am looking at the next challenge… :slight_smile: but that’s how you grow, right?

Thanks for the videos - certainly makes sense to collect them in the topic.

1 Like

That worked! I appreciate you sharing this.