Italian (Italy)
Knowledge Base  >  Vik Appointments  >  Hook  >  Cancellazione  >  Check Appointment

apply_filters( 'vikappointments_check_appointment_cancellation', bool $allow, object $appointment )

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


Description

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.

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


Parameters

$allow

(bool)  Use false to deny the cancellation.

$reservation

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


Example

The example below prevents the cancellation for those customers that never booked an appointment. In summary, the cancellation will be allowed starting from the second 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  object   $appointment  The appointment to check.
 */
add_filter('vikappointments_check_appointment_cancellation', function($allow, $appointment)
{
    if ($appointment->id_user <= 0)
    {
        // only registered user can request a cancellation
        return false;
    }

    $dbo = JFactory::getDbo();

    $q = $dbo->getQuery(true)
        ->select(1)
        ->from($dbo->qn('#__vikappointments_reservation'))
        // take only confirmed and paid appointments
        ->where($dbo->qn('status') . ' IN (\'C\', \'P\')')
        // make sure we have an appointment in the past
        ->where($dbo->qn('checkin_ts') . ' < ' . $dbo->q(JFactory::getDate()->toSql()))
        // take only the appointments assigned to this user
        ->andWhere(array(
            $dbo->qn('id_user') . ' = ' . $appointment->id_user,
            $dbo->qn('createdby') . ' = ' . $appointment->id_user,
        ), 'OR');

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

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

Changelog

Version Description
1.2 Introduced.
Ultimo aggiornamento: 2021-07-28
Utile?
This site uses cookies. By continuing to browse you accept their use. Further information