Your cart is empty!
Calculate Minimum Cost
public function onCalculateOrderMinCost( float $cost, array $args ) : float
Fires while fetching the minimum cost for ordering.
Description
Plugins can use this hook to override at runtime the minimum cost for food ordering.
Parameters
- $cost
-
(float) The minimum cost based on configuration and delivery area.
- $args
-
(array) An associative array containing the order query.
date
- the check-in date of the order, formatted according to the configuration;hourmin
- the check-in time of the order, using the 24H format;delivery
- true in case of delivery service, false in case of pickup.
Return Value
Float. The minimum cost to use.
Example
The example below increases the minimum total for order placed outside the weekend and which require a delivery.
/**
* Plugins can use this hook to override the minimum cost at runtime.
*
* @param float $cost The minimum cost based on configuration and delivery area.
* @param array $args An associative array containing the order query.
*
* @return float The minimum cost to use.
*/
public function onCalculateOrderMinCost($cost, $args)
{
// check if we have a delivery service
if ($args['delivery']) {
// extract hours and minutes
list($h, $m) = explode(':', $args['hourmin']);
// create timestamp
$ts = VikRestaurants::createTimestamp($args['date'], (int) $h, (int) $m);
// get day of the week
$w = (int) date('w', $ts);
// check whether the day is included between Mon and Thu
if ($w >= 1 && $w <= 4) {
// increase minimum cost by 5
$cost += 5;
}
}
return $cost;
}
Changelog
Version | Description |
---|---|
1.8.3 | Introduced. |
Last Update: 2023-12-29 14:15
Helpful?