public function onBeforeApplyCartDiscount( Discount $discount, float $amount, Item $item ) : bool

Fires before calculating the discount applied by a coupon or a deal to a specific item.


Description

Plugins attached to this hook can prevent the system from applying the discount.

NOTE: calling $discount->apply() in this hook will result in recursion.


Parameters

$discount

(Discount)  The object holding the discount information. This class is part of the E4J\VikRestaurants\TakeAway\Cart\Deals namespace.

$amount

(float)  The initial amount to discount.

$item

(Item)  The object holding the details of the item to discount. This class is part of the E4J\VikRestaurants\TakeAway\Cart namespace.

Return Value

Boolean. False to prevent the system from applying the discount to the given item.


Example

The example below prevents the system from discounting all the items under the menu with ID 5.

/**
 * Trigger event to let external plugins prevent the application of the
 * discount at runtime. Useful in example to ignore the discount for
 * certain items and options.
 *
 * @param   Discount  $discount  The discount information.
 * @param   float     $amount    The initial amount to discount.
 * @param   Item      $item      The item to discount.
 *
 * @return  bool      True to apply the discount, false otherwise.
 */
public function onBeforeApplyCartDiscount($discount, $amount, $item)
{
    // check if the item belongs to "beverages" menu (ID: 5)
    return $item->getMenuID() != 5;
}

Changelog

Version Description
1.9 Introduced.
Last Update: 2023-12-29 14:15
Helpful?