You are here

function commerce_tax_total_amount in Commerce Core 7

Returns the total amount of tax included in a price components array.

Parameters

$components: A price's components array including potential tax components.

$included: Boolean indicating whether or not to include in the total taxes that were included in the price amount already.

$currency_code: The currency to return the tax amount in.

Return value

The consolidated tax collected for an order expressed as an integer amount.

File

modules/tax/commerce_tax.module, line 598
Defines tax rates and Rules integration for configuring tax rules for applicability and display.

Code

function commerce_tax_total_amount($components, $included, $currency_code) {
  $component_types = commerce_tax_commerce_price_component_type_info();
  $amount = 0;

  // Loop over each component passed in...
  foreach ($components as $component) {

    // Looking for components that match one of the defined tax price components.
    if (array_key_exists($component['name'], $component_types)) {

      // If the component matches the requested "included" value...
      if (!$included && empty($component['included']) || $included && !empty($component['included'])) {

        // Add the converted price amount to the running total.
        $amount += commerce_currency_convert($component['price']['amount'], $component['price']['currency_code'], $currency_code);
      }
    }
  }
  return $amount;
}