You are here

function hook_commerce_currency_info in Commerce Core 7

Defines currencies available to the Commerce currency formatting and price APIs.

By default Drupal Commerce defines all actively traded currencies according to ISO 4217. Additional currencies may be added by modules that depend on alternate or pseudo-currency definitions.

Return value

An array of currency data arrays keyed by three character currency codes. Currency data arrays should include:

  • code: The uppercase alphabetic currency code. For example USD.
  • numeric_code: The numeric currency code. According to ISO4217 this code consists of three digits and first digit can be a zero.
  • symbol: The currency symbol. For example $.
  • name: The name of the currency. Translatable.
  • symbol_placement: Defines where the currency symbol has to be placed for display. Allowed values: before, after, hidden.
  • symbol_spacer: The spacer to put between the price amount and a currency symbol that appears after the amount; defaults to ' '.
  • code_placement: Defines where the currency code has to be placed for display. Allowed values: before, after, hidden.
  • code_spacer: The spacer to put between the price amount and currency code whether the code is displayed before or after the amount; defaults to ' '.
  • minor_unit: Name of the minor unit of the currency. For example Cent. Translatable
  • major_unit: Name of the major unit of the currency. For example Dollar. Translatable
  • rounding_step: Defines which stepping has to is used for price rounding. For example Swiss Francs use a rounding_step of 0.05. This means a price like 10.93 is converted to 10.95. Currently only the steps 0.5,0.05... and 0.2, 0.02 ... are supported. This value has to be defined as string, otherwise the rounding results can be unpredictable. Default: 0 (no special rounding)
  • decimals: The number of decimals to display. Default: 2
  • thousands_separator: The char to split the value in groups of thousand. Default: ,
  • decimal_separator: The char to split the integer from the decimal part. Default: .
  • format_callback: Custom callback function to format a price value.
  • conversion_callback: Custom callback function to convert a price amount from one currency into another.
  • conversion_rate: The conversion rate of this currency calculated against the base currency, expressed as a decimal value denoting the value of one major unit of this currency when converted to the base currency. Default: 1

See also

hook_commerce_currency_info_alter()

1 function implements hook_commerce_currency_info()

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

commerce_commerce_currency_info in includes/commerce.currency.inc
Implements hook_commerce_currency_info().
1 invocation of hook_commerce_currency_info()
commerce_currencies in ./commerce.module
Returns an array of all available currencies.

File

./commerce.api.php, line 59
This file contains no working PHP code; it exists to provide additional documentation for doxygen as well as to document hooks in the standard Drupal manner.

Code

function hook_commerce_currency_info() {
  return array(
    'CHF' => array(
      'code' => 'CHF',
      'numeric_code' => '756',
      'symbol' => 'Fr.',
      'name' => t('Swiss Franc'),
      'symbol_placement' => 'before',
      'code_placement' => 'before',
      'minor_unit' => t('Rappen'),
      'major_unit' => t('Franc'),
      'rounding_step' => '0.05',
    ),
  );
}