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 tax 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. takeaway.item 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.
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 int $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)
{
if (!isset($options['id_user'])) {
// use default taxes if we are not dealing with a customer
return $id_tax;
}
// load customer details
$customer = VikRestaurants::getCustomer($options['id_user']);
if (empty($customer->vatnum)) {
// customers without a VAT number, use tax #1
return 1;
}
// otherwise use tax #2
return 2;
}
Changelog
Version | Description |
---|---|
1.9 | Introduced. |
Last Update: 2023-12-29 14:15
Helpful?