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

apply_filters( 'vikappointments_before_calculate_total_save_order', bool $status, VAPCart $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, starting from 1.2 version, it is no more possible to change the total cost and the user credit at runtime. Any surcharge/discount have now to be applied by using the apposite methods provided by the cart objects.


Parameters

$status

(bool)  True on success, false otherwise.

$cart

(VAPCart)  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  VAPCart  $cart    The cart instance.
 * @param  object   $user    The user details.
 */
add_filter('vikappointments_before_calculate_total_save_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 Added $cart argument.
Removed $total and $credit arguments.
1.0 Introduced.
Last Update: 2021-08-05
Helpful?

This website uses cookies

This website uses cookies and similar technologies. Some of these technologies are necessary for the proper functioning of the website (Essential). Other technologies are used to evaluate user behavior (Analysis), to integrate external media or for advertising purposes. If you agree, these technologies are activated. For details, please refer to the privacy policy. From this same page you can also update/revoke your consent. If you do not give your consent, only cookies with essential functions will be activated.

We use technologies from the USA on our website. If you give your consent, you therefore consent at the same time to your data being transferred to the USA. We would like to point out that the USA does not have a level of data protection comparable to that of the EU and that any US company can be obliged by state authorities to hand over your data without you having any effective legal protection against this.