Skip to content

Add taxes to hook_taxcalculator_alter_lineitems

samuelsov requested to merge samuelsov/taxcalculator:Hook into master

In hook_taxcalculator_alter_lineitems, we sometimes need to have the details of the current tax definition if we want to remove provincial taxes in some context for example.

usage:

function myext_cdntaxcalculator_alter_lineitems(&$line_items, $taxes) {
  foreach ($line_items as &$item) {
    if (isset($item['membership_type_id']) && !empty($item['membership_type_id'])) {
      // remove PST for membership related prices
      $item['tax_rate'] = $taxes['HST_GST'];
      $item['tax_amount'] = $item['tax_rate'] * $item['amount'] / 100;
    }
  } 
}

Merge request reports

Loading