English (United Kingdom)
Knowledge Base  >  Vik Appointments  >  Hooks  >  Purchase  >  Packages  >  Before Calculate Total

apply_filters( 'vikappointments_before_calculate_total_save_packages_order', bool $status, VAPCartPackages $cart, object $user )

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

$status

(bool)  True on success, false otherwise.

$cart

(VAPCartPackages)  The cart instance.

$user

(object)  An object holding the details of the current user.


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  boolean          $status  True on success, false otherwise.
 * @param  VAPCartPackages  $cart    The cart instance.
 * @param  object           $user    The user details.
 */
add_filter('vikappointments_before_calculate_total_save_packages_order', function($status, $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);

    return $status;
}, 10, 3);

Changelog

Version Description
1.2 Introduced.
Last Update: 2021-08-05
Helpful?