Format Select Option
apply_filters( 'vikrestaurants_format_time_select_option', string $text, object $time, int $step, object $shift, int $group )
Fires while formatting the text of the option belonging to the dropdown used to pick a time.
Description
This hook is triggered to let external plugins format the text to show within the options of the time dropdown.
Fires for each option within the time dropdown.
Parameters
- $text
-
(string|null) The text to show for the given time option.
At the first hook execution, the argument may be a
null
value. - $time
-
(object) The object holding the details of the time option. The
format
property will report the default text that will be used in case of no manipulation. - $step
-
(int) The minutes of interval between this time and the next one.
- $shift
-
(object) The object holding the details of the current working shift.
- $group
-
(int) The section to which the time refers,
1
for restaurant and2
for take-away.
Example
The example below displays approximative times for the take-away availability dropdown. In example, instead of 8:00 pm, the system will display 8:00 pm - 8:20 pm.
/**
* Trigger filter to let external plugins format the text to
* show within the options of the time dropdown.
*
* @param string $text The text to display.
* @param object $time The object holding the time details.
* @param int $step The minutes between this time and the next one.
* @param object $shift The object holding details of the current shift.
* @param int $group The section to which the times refer (1: restaurant, 2: take-away).
*/
add_filter('vikrestaurants_format_time_select_option', function($text, $time, $step, $shift, $group) {
// observe only take-away times
if ($group == 2) {
// create delimiter time by adding the interval length
$end = $time->hour * 60 + $time->min + $step;
// get a readable time string
$end = JHtml::_('vikrestaurants.min2time', $end);
// create approx. text
$text = $time->format . ' - ' . $end;
}
return $text;
}, 10, 5);
Changelog
Version | Description |
---|---|
1.2.1 | Introduced. |