You are here

function hook_commerce_tax_rate_info in Commerce Core 7

Defines tax rates that may be applied to line items.

Modules that integrate third party tax calculation services still need to define tax rates that correspond to the price components they use to store those calculated taxes on line items. Otherwise modules that attempt to communicate the amount of tax on an order to other systems will not get accurate total tax amounts.

To do this, a tax rate should be defined that may have a rate of 0 and an undefined tax type, but they should likely not specify a default Rules component, should not show in the administrative list, and should use a calculation callback that simply returns FALSE (unless the tax services supports tax calculation on a line item basis as opposed to requiring an entire order to return taxes).

Return value

An array of information about available tax rates. The returned array should be an associative array of tax rate arrays keyed by the tax rate name. Each tax rate array can include the following keys:

  • title: the title of the tax rate; must be defined
  • display_title: a display title for the tax type suitable for presenting to customers if necessary; defaults to the title
  • description: a short description of the tax rate
  • rate: the percentage used to calculate this tax expressed as a decimal
  • type: the name of the tax type this rate belongs to
  • rules_component: name of the Rules component (if any) defined for determining the applicability of the tax to a line item; defaults to 'commerce_tax_rate_[name]'. If the tax rate name is longer than 46 characters, it must have a Rules component name set here that is 64 characters or less.
  • default_rules_component: boolean indicating whether or not the Tax module should define a default default Rules component using the specified name; defaults to TRUE.
  • price_component: name of the price component defined for this tax rate used when the tax is added to a line item; if set to FALSE, no price component will be defined for this tax rate
  • admin_list: boolean defined by the Tax UI module determining whether or not the tax rate should appear in the admin list
  • calculation_callback: name of the function used to calculate the tax amount for a given line item, returning either a tax price array to be added as a component to the line item's unit price or FALSE to not include anything; defaults to 'commerce_tax_rate_calculate'.
1 function implements hook_commerce_tax_rate_info()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

commerce_tax_ui_commerce_tax_rate_info in modules/tax/commerce_tax_ui.module
Implements hook_commerce_tax_rate_info().
1 invocation of hook_commerce_tax_rate_info()
commerce_tax_rates in modules/tax/commerce_tax.module
Returns an array of tax rate objects keyed by name.

File

modules/tax/commerce_tax.api.php, line 145
Documents hooks provided by the Tax module.

Code

function hook_commerce_tax_rate_info() {
  $tax_rates = array();
  $tax_rates['ky_sales_tax'] = array(
    'title' => t('KY sales tax'),
    'rate' => 0.06,
    'type' => 'sales_tax',
  );
  return $tax_rates;
}