Your cart is empty!
Before Use
public function onBeforeUseTax(int $id_tax, array $options) : mixed
Fires before assigning the taxes to apply.
Description
Trigger hook to allow external plugins to switch tax ID at runtime, which may vary according to the specified options.
Parameters
- $id_tax
-
(int) The default ID assigned to the specified object.
- $options
-
(array) An associative array of options.
subject
- the entity to which the TAX refers. When specified, the$id_tax
argument is equals to the ID of the given subject (e.g. service with ID 7). In that case, the system will load the tax ID assigned to the specified record.lang
- the language tag specified by the user.id_user
- the ID of the customer that is going to purchase something (missing whenid_employee
is specified).id_employee
- the ID of the employee that is going to purchase a subscription (missing whenid_user
is specified).
Return Value
Boolean or integer. The new ID of the tax to apply or false to ignore the taxes calculation.
Example
The example below switches at runtime the taxes to use according to the type of customers. Tax #1 will apply to those customers that don't own a VAT number, otherwise tax #2 will be applied.
/**
* Trigger hook to allow external plugins to switch tax ID at
* runtime, which may vary according to the specified options.
*
* @param integer $id_tax The current tax ID.
* @param array $options An array of options.
*
* @return mixed The ID of the tax to apply or false
* to ignore the taxes calculation.
*/
public function onBeforeUseTax($id_tax, $options)
{
// init return value
$use = $id_tax;
if (!isset($options['id_user'])
{
// use default taxes if we are not dealing with a customer
return $use;
}
// load customer details
$customer = VikAppointments::getCustomer($options['id_user']);
if (empty($customer->vatnum))
{
// customers without a VAT number, use tax #1
$use = 1;
}
else
{
// otherwise use tax #2
$use = 2;
}
return $use;
}
Changelog
Version | Description |
---|---|
1.7 | Introduced. |
Last Update: 2021-10-08 16:05
Helpful?