English (United Kingdom)

apply_filters( 'vikappointments_after_build_timeline', bool $show, mixed $timeline )

Fires after constructing the object wrapping the timeline.


Description

Fires an event to manipulate the timeline without having to create a new parser. Does not trigger in case the timeline building returned an invalid instance.

NOTE: throw an exception to prompt a message to the front-end user to explain why the timeline is not visible.


Parameters

$show

(bool)  False to prevent the timeline from showing.

$timeline

(VAPAvailabilityTimeline)  The timeline wrapper.


Example

The example below explains how to work with the timeline object.

/**
 * Fire an event to manipulate the timeline without having to create a new parser.
 * DO NOT trigger in case the timeline building returned an invalid instance.
 * 
 * Throw an exception to display an error message to the front-end user.
 *
 * @param  bool                     $show      False to prevent the timeline building.
 * @param  VAPAvailabilityTimeline  $timeline  The timeline object.
 */
add_filter('vikappointments_after_build_timeline', function($show, $timeline)
{
    // iterate all the times by using the iterator interface
    foreach ($timeline as $level) {
        foreach ($level as $time) {
            // look for available times only
            if ($time->isAvailable() == false) {
                continue;
            }

            if ($time->checkin('G') % 2 === 0) {
                // in case of even hour, turn off the availability
                $time->setStatus(0);
            } else {
                // in case of odd hour, double the price
                $time->setPrice($time->price * 2);
            }
        }
    }

    return $show;
}, 10, 2);

Changelog

Version Description
1.2.12 Introduced.
Last Update: 2024-05-14
Helpful?
See Also:
This site uses cookies. By continuing to browse you accept their use. Further information