Italian (Italy)
Knowledge Base  >  Vik Appointments  >  Hook  >  Carrello  >  Appuntamenti  >  Before Apply Discount

apply_filters( 'vikappointments_before_apply_cart_discount', bool $status, VAPCartDiscount $discount, float $amount, mixed $item )

Fires before calculating the discount to apply.


Description

Trigger hook to let external plugins prevent the application of the discount at runtime. The hook triggers once for each discount to apply and iterates for all the items and options contained within the user cart.

Useful in example to ignore the discount for certain items and options.

NOTE: since the $item instance may vary, it is opportune to check the entity of the object first, such as the following example.

if ($item instanceof VAPCartItem)
{
    $id = $item->getServiceID();
}
else
{
    $id = $item->getID();
}

Parameters

$status

(bool)  True on success, false otherwise.

$discount

(VAPCartDiscount)  The instance holding the discount details.

$amount

(float)  The cost of the item.

$item

(mixed)  The instance holding the details of the item to discount.


Example

The following example avoids to apply a discount for certain services.

/**
 * Trigger hook to let external plugins prevent the application of the
 * discount at runtime.
 *
 * @param  boolean          $status    True on success, false otherwise.
 * @param  VAPCartDiscount  $discount  The discount instance.
 * @param  float            $amount    The amount to discount.
 * @param  mixed            $item      The item instance.
 */
add_filter('vikappointments_before_apply_cart_discount', function($status, $discount, $amount, $item)
{
    // do not apply discount for services with ID 1, 2 and 3
    $list = [1, 2, 3];

    // check whether the service is discountable or not
    if ($item instanceof VAPCartItem && in_array($item->getServiceID(), $list))
    {
        // do not apply discount
        return false;
    }
	
    // apply discount
    return true;
}, 10, 4);

Changelog

Version Description
1.2 Introduced.
Ultimo aggiornamento: 2021-10-06
Utile?
Potrebbe interessarti:

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.