Your cart is empty!
Before Calculate Total
public function onBeforeCalculateTotalSavePackagesOrder(VAPCartPackages $cart, object $user) : void
Fires before calculating the order totals.
Description
Trigger hook to manipulate the total cost before it is going to be calculated.
The prices of the cart are strictly related to the taxes and to the discounts. For this reason it is not possible to change the total cost and the user credit at runtime. Any surcharge/discount have to be applied by using the apposite methods provided by the cart objects.
Parameters
- $cart
-
(VAPCartPackages) The cart instance.
- $user
-
(object) An object holding the details of the current user.
Return Value
None.
Example
The following example explains how to apply a custom discount.
/**
* Trigger hook to manipulate the total cost before it is going to be calculated.
*
* @param VAPCartPackages $cart The cart instance.
* @param object $user The user details.
*
* @return void
*/
public function onBeforeCalculateTotalSavePackagesOrder($cart, $user)
{
// create new discount rule
$discount = new VAPCartDiscount(
$alias = 'custom-discount',
$amount = 20.00,
$is_percent = true
);
// register discount within the cart
$cart->addDiscount($discount);
}
Changelog
Version | Description |
---|---|
1.7 | Introduced. |
Last Update: 2021-10-08 15:08
Helpful?