Thank you for waiting and here are my findings.
The use of repeatable field groups is useful when working with items that are infinite or variable in numbers. However, in the case of weekdays which are fixed in number (7), it can result in an unnecessary complication.
On my test website, I added 7 single line type custom fields for each day of the week (without any repeatable field group):
- monday-hours
- tuesday-hours
- wednesday-hours
- thursday-hours
- friday-hours
- saturday-hours
- sunday-hours
In these fields, I added the opening and closing hours in the same format as they're added on your website, e.g.
9am-5pm
4am-7pm
10pm-11pm
etc.
Next, I needed the custom shortcode, which can get the custom field value from the field which has today's day in its slug and then compare the current time with the opening and closing hours on that day. If the current time falls within that hour range, then it returns 'yes' (means it is open) and if not, it returns 'no' (means not open):
add_shortcode('custom_open_check', 'custom_open_check_func');
function custom_open_check_func( $atts ) {
global $post;
$a = shortcode_atts( array(
'id' => $post->ID
), $atts );
$day = strtolower(date('l'));
$field_slug = $day.'-hours';
$field_value = types_render_field( $field_slug, array( 'item' => $a['id'], 'output' => 'raw' ) );
$field_value_arr = explode('-', $field_value);
$current_time = current_time( 'timestamp' );
$startdatetime = new DateTime($field_value_arr[0]);
$enddatetime = new DateTime($field_value_arr[1]);
if(($startdatetime->format('U') <= $current_time) && ($current_time <= $enddatetime->format('U'))) {
return 'yes';
}
else
{
return 'no';
}
}
The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.
After that, you can use this shortcode in the conditional blocks in your content template or views to show or hide particular content or results based on whether the practitioner is open or not.
I hope this helps and let me know if any point is not clear.
Note: The custom code examples from our forum are shared to get you started in the right direction. You're welcome to adjust them as needed and for more personalized customization assistance, you can consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/