Home › Forums › General Issues › Opening hours with NOW Opened/Closed
Hi guys,
did anyone do Opening Hours with ACF?
I mean, I have this table:
Monday: 08:00 – 11:30 12:30 – 16:00
Tuesday: 08:00 – 11:30 12:30 – 15:00
Wednesday: 08:00 – 11:30 12:30 – 16:00
Thursday: 08:00 – 11:30 12:30 – 15:00
Friday: 08:00 – 11:30 12:30 – 14:00
And apart from that, I would like to create a simplified view of Opening Hours, which would say:
Now it’s OPEN. Will be open for X hours and X minutes.
or
Now it’s CLOSED. Will open in X hours and X minutes.
Is that possible to do with ACF? Can you advise how? Any pointing in the right direction will help.
I am not an ACF expert at all. I am just learning it, too. There is some great support, in my experience, here but I suggest you try to explain what you have tried thus far.
One idea is to make open hours and day a repeater field? You could have a dropdown to select the day of the week, and a text box for open time and a text box for close time in 24 hour format, for example. You could also use a time picker to ‘from’ and ‘to’ instead of input boxes. This way you could have several entries for each day (eg. one entry: Monday 0900 1200, next entry: Monday 1300 1700).
Once you have above working, you would just grab the current time and day.
$day = date('w', $timestamp); // just one example
Above would return a number from 0 to 6. 0 is Sunday and 6 is Saturday.
Then you would loop the repeater field to find that day if it existed.
Then you would grab the time. Lots of ways to do that.
Then you would loop the repeater field to see if it falls between from/to.
If true, it is open and you just need to calculate the current time to the next close time and then maybe the next open time. If false, you would search for the next open day and time and calculate the time.
Maybe you could add another field to log national holidays or other closed days. It could be a date with a input field for comments. The first loop would test to see if today was a national holiday or a store closer and echo the comment field could mention the reason why the store was closed.
Just ideas. Hope this helps. Try to get the first step of capturing the day, from-time and to-time in a repeater field.
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.