English (United Kingdom)
Knowledge Base  >  Vik Restaurants  >  Hooks  >  Take-Away  >  Calculate Maximum Orders

apply_filters( 'vikrestaurants_calculate_max_orders_per_interval', int $max, int $default, array $times, object $slot, mixed $search )

Fires while fetching the maximum number of accepted orders per interval.


Description

Plugins can use this hook to change at runtime the maximum number of accepted orders per interval.

NOTE: it is possible to use $slot->ordersCount to retrieve the total number of orders that were placed for this time slot. Only the orders with the same service specified from the configuration will be counted. In case you decided to limit the orders only for delivery service, any pickup order won't be counted.


Parameters

$max

(int)  The new maximum value.

$default

(int)  The default maximum value.

$times

(array)  The current working shift and all the related timeslots.

$slot

(object)  The current timeslot/interval.

$search

(VREAvailabilityTakeaway)  The instance used to fetch the times availability.


Example

The example below doubles the maximum number of accepted orders for purchases made in the week-end.

/**
 * Plugins can use this hook to change at runtime the maximum number of orders per slot. 
 *
 * @param  integer  $max      The new maximum amount.
 * @param  integer  $default  The default amount.
 * @param  array    $times    The current working shift and all the related timeslots.
 * @param  object   $slot     The current timeslot.
 * @param  mixed    $search   The availability search instance.
 */
add_filter('vikrestaurants_calculate_max_orders_per_interval', function($max, $default, $times, $slot, $search)
{
    // extract hours and minutes
    list($h, $m) = explode(':', $slot->value);
    // create timestamp
    $ts = VikRestaurants::createTimestamp($search->get('date'), (int) $h, (int) $m);
    // get day of the week
    $w = (int) date('w', $ts);

    // check whether the day is included between Fri and Sun
    if (in_array($w, [0, 5, 6]))
    {
        // check whether the amount has been already manipulated
        $max = is_null($max) ? $default : $max;
        // double maximum amount
        $max *= 2;
    }

    return $max;
}, 10, 5);

Changelog

Version Description
1.2 Introduced.
Last Update: 2021-01-26
Helpful?
This site uses cookies. By continuing to browse you accept their use. Further information