Italian (Italy)
Knowledge Base  >  Vik Restaurants  >  Hooks  >  Cancellazione  >  Controllo Prenotazione

apply_filters( 'vikrestaurants_check_reservation_cancellation', bool $allow, object $reservation )

Fires while checking whether the cancellation is allowed for the specified reservation.


Description

This filter can be used to apply additional conditions to the cancellation restrictions. Applies only for restaurant reservations.

When this hook is triggered, the system already validated the standard conditions and the cancellation has been approved for the usage.

In case of allowed cancellation, the page containing the reservation details will report a button to cancel the reservation.


Parameters

$allow

(bool)  Use false to deny the cancellation.

$reservation

(VREOrderRestaurant)  An object containing the details of the reservation that is going to be cancelled.


Example

The example below prevents the cancellation for those customers that never booked a table. In summary, the cancellation will be allowed starting from the second table booking.

/**
 * This filter can be used to apply additional conditions to the 
 * cancellation restrictions. When this hook is triggered, the
 * system already validated the standard conditions and the
 * cancellation has been approved for the usage.
 *
 * @param  boolean  $allow        Use false to deny the cancellation.
 * @param  mixed    $reservation  The restaurant reservation to check.
 */
add_filter('vikrestaurants_check_reservation_cancellation', function($allow, $reservation)
{
    if ($reservation->id_user <= 0)
    {
        // only registered user can request a cancellation
        return false;
    }

    $dbo = JFactory::getDbo();

    $q = $dbo->getQuery(true)
        ->select(1)
        ->from($dbo->qn('#__vikrestaurants_reservation'))
         ->where($dbo->qn('status') . ' IN ("C", "P")')
        ->where($dbo->qn('id') . ' <> ' . $reservation->id)
        ->where($dbo->qn('id_parent') . ' <> ' . $reservation->id)
        ->andWhere(array(
            $dbo->qn('id_user') . ' = ' . $reservation->id_user,
            $dbo->qn('created_by') . ' = ' . $reservation->id_user,
        ), 'OR');

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

    // prevent cancellation in case of no existing reservations
    // assigned to this customer
    return $dbo->getNumRows() ? true : false;
}, 10, 2);

Changelog

Version Description
1.0 Introduced.
Ultimo aggiornamento: 2024-01-03
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.