Italian (Italy)
Knowledge Base  >  Vik Restaurants  >  Hooks  >  Conferme  >  Controllo Ordine

apply_filters( 'vikrestaurants_check_order_self_confirmation', bool $allow, object $order )

Fires while checking whether the self-confirmation is allowed for the specified order.


Description

This filter can be used to apply additional conditions to the self-confirmation restrictions. Applies only for take-away orders.

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

In case of allowed confirmation, the customer will be able to self-confirm a PENDING order through an apposite link received via e-mail.


Parameters

$allow

(bool)  Use false to deny the confirmation.

$order

(VREOrderTakeaway)  An object containing the details of the order that is going to be confirmed.


Example

The example below prevents the confirmation for those customers that never purchased a take-away order. In summary, the confirmation will be allowed starting from the second purchase.

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

    $dbo = JFactory::getDbo();

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

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

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

Changelog

Version Description
1.0 Introduced.
Ultimo aggiornamento: 2024-01-03
Utile?