Italian (Italy)
Knowledge Base  >  Vik Restaurants  >  Hooks  >  Take-Away  >  Calculate Maximum Meals

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

Fires while fetching the maximum number of meals that can be prepared on each interval.


Description

Plugins can use this hook to change at runtime the maximum number of preparation meals per slot.

NOTE: it is possible to use $slot->count to retrieve the total number of preparation items that were scheduled for this time slot. Only the items with No Preparation option turned off will be counted here.


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 items that can be prepared 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_preparation_meals', 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.
Ultimo aggiornamento: 2021-01-26
Utile?