English (United Kingdom)
Knowledge Base  >  Vik Restaurants  >  Hooks  >  Take-Away Cart  >  After Apply Discount

do_action_ref_array( 'vikrestaurants_after_apply_cart_discount', float &$value, Discount $discount, float $amount, Item $item )

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


Description

Plugins attached to this hook can manipulate the discount amount calculated by the system for a specific item.

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


Parameters

&$value

(float)  The discount calculated by the system, passed by reference.

$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.


Example

/**
 * Trigger event to let external plugins alter the discount to apply at runtime.
 *
 * @param  float     &$value    The calculated discount value.
 * @param  Discount  $discount  The discount information.
 * @param  float     $amount    The initial amount to discount.
 * @param  Item      $item      The item to discount.
 */
add_action('vikrestaurants_after_apply_cart_discount', function($value, $discount, $amount, $item) {
    /**
     * @todo it is possible to manipulate $value here to change the applied discount
     */
}, 10, 4);

Changelog

Version Description
1.3 Introduced.
Last Update: 2024-01-04
Helpful?