Hello all,
I’ve started using ACF for a project of mine that works as business directory. For each business (place) I want to register the working days and hours.
The structure I created is like this:
[Group Field] Name of the day (Monday, Tuesday, etc)
[True/False Field] Open All Day
[True/False Field] Closed All Day
[Repeater Field] Time Entries
[Time Picker Field. Display/Return Format H:i] Open Time
[Time Picker Field. Display/Return Format H:i] Closing Time
Using code to create entries, I’ve managed to set the Open/Closed All Day fields, but I am not able to set the Time Entries.
I’ve tried several different formats of this code:
foreach ( $workingHours as $workingHour ) {
$day = $workingHour->en;
// Update all day open/closed fields
update_field( "{$day}_all_day_open", $workingHour->allDayOpen, $post_id );
update_field( "{$day}_all_day_close", $workingHour->allDayClosed, $post_id );
if (
true === $workingHour->allDayOpen ||
true === $workingHour->allDayClosed
) {
continue;
}
$time_entries = [];
if ( ! empty( $workingHour->workingHours ) ) {
foreach ( $workingHour->workingHours as $hour ) {
$time_entries[] = [
"open_time" => $hour->opening,
"closing_time" => $hour->closing,
];
}
}
update_field( "{$day}_time_entries", $time_entries, $post_id );
}
Can someone help fix that issue?