English (United Kingdom)
Knowledge Base  >  Vik Restaurants  >  Hooks  >  Reservation  >  Calculate Total Deposit

apply_filters( 'vikrestaurants_calculate_total_deposit', float $deposit, float $total, array $args )

Fires while calculating the deposit amount to use for restaurant reservations.


Description

This filter can be used to alter at runtime the total deposit to leave for confirming a restaurant reservation.


Parameters

$deposit

(float|null)  The new deposit amount. Leave null to use the default deposit.

$total

(float)  The default deposit amount.

$args

(array)  An associative array containing the query arguments.

  • date - the check-in date, formatted according to the configuration of the plugin;
  • hourmin - the check-in time, always in 24H format;
  • people - the number of participants;
  • table - the table that will be assigned to the reservation.

Example

The example below uses a different deposit depending on the room that has been selected.

/**
 * This filter can be used to alter the total deposit at runtime.
 *
 * @param  float  $deposit  The new deposit amount.
 * @param  float  $total    The default deposit.
 * @param  array  $args     The searched arguments.
 */
add_filter('vikrestaurants_calculate_total_deposit', function($deposit, $total, $args)
{
    $dbo = JFactory::getDbo();

    $q = $dbo->getQuery(true)
        ->select($dbo->qn('id_room'))
        ->from($dbo->qn('#__vikrestaurants_table'))
        ->where($dbo->qn('id') . ' = ' . (int) $args['table']);

    $dbo->setQuery($q, 0, 1);
    $dbo->execute();

    if ($dbo->getNumRows())
    {
        switch ($dbo->loadResult())
        {
            case 1:
                // leave amount as it is for "main room"
                break;

            case 2:
                // unset deposit for "garden"
                $deposit = 0;
                break;

            case 3:
                // double deposit for "private room"
                $deposit = $total * 2;
                break;
        }
    }

    return $deposit;
}, 10, 3);

Changelog

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