Italian (Italy)
Knowledge Base  >  Vik Restaurants  >  Hooks  >  Take-Away  >  Calculate Minimum Cost

apply_filters( 'vikrestaurants_calculate_order_min_cost', float $cost, float $default, array $args )

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 to use.

$default

(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.

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 to use.
 * @param  float  $default  The minimum cost based on configuration and delivery area.
 * @param  array  $args     An associative array containing the order query.
 */
add_filter('vikrestaurants_calculate_order_min_cost', function($cost, $default, $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)
        {
            // check whether the cost has been already manipulated
            $cost = is_null($cost) ? $default : $cost;
            // increase minimum cost by 5
            $cost += 5;
        }
    }

    return $cost;
}, 10, 3);

Changelog

Version Description
1.2 Introduced.
Ultimo aggiornamento: 2021-01-26
Utile?

Questo sito web utilizza i cookie

Questo sito web utilizza cookie e tecnologie simili. Alcune di queste tecnologie sono necessarie per il corretto funzionamento del sito web (essenziali). Altre tecnologie sono utilizzate per valutare il comportamento degli utenti (analisi), per integrare media esterni o per scopi pubblicitari. Se l'utente accetta, queste tecnologie vengono attivate. I dettagli sono riportati nella Privacy Policy. Da questa stessa pagina è inoltre possibile aggiornare/revocare il consenso. Se non si fornisce il consenso, verranno attivati solo i cookie con funzioni essenziali.

Sul nostro sito web utilizziamo tecnologie provenienti dagli Stati Uniti. Pertanto, se acconsentite, acconsentite anche al trasferimento dei vostri dati negli Stati Uniti. Desideriamo sottolineare che gli Stati Uniti non hanno un livello di protezione dei dati paragonabile a quello dell'Unione Europea e che qualsiasi azienda statunitense può essere obbligata dalle autorità statali a consegnare i vostri dati senza che voi abbiate alcuno strumento efficace di protezione legale contro questo.