gform_currencies

Description

The gform_currencies filter can be used to update existing currencies and/or create new currencies.

Usage

add_filter( 'gform_currencies', 'your_function_name' );

Parameters

  • $currencies array
    An array of registered currencies using the three character ISO 4217 currency code as the key to an array containing the currency properties. The default array includes the properties of the following currencies:
    • USD – U.S. Dollar
    • GBP – Pound Sterling
    • EUR – Euro
    • AUD – Australian Dollar
    • BRL – Brazilian Real
    • CAD – Canadian Dollar
    • CZK – Czech Koruna
    • DKK – Danish Krone
    • HKD – Hong Kong Dollar
    • HUF – Hungarian Forint
    • ILS – Israeli New Sheqel
    • JPY – Japanese Yen
    • MYR – Malaysian Ringgit
    • MXN – Mexican Peso
    • NOK – Norwegian Krone
    • NZD – New Zealand Dollar
    • PHP – Philippine Peso
    • PLN – Polish Zloty
    • RUB – Russian Ruble
    • SGD – Singapore Dollar
    • ZAR – South African Rand
    • SEK – Swedish Krona
    • CHF – Swiss Franc
    • TWD – Taiwan New Dollar
    • THB – Thai Baht

Currency Properties

  • name string
    The currency name, e.g. Euro
  • code string
    The three character ISO 4217 currency code.
  • symbol_left string
    An empty string or the decimal reference (e.g. €), HTML entity (e.g. €), or symbol (e.g. ) to be displayed on the right side of the value.
  • symbol_right string
    An empty string or the decimal reference (e.g. €), HTML entity (e.g. €), or symbol (e.g. ) to be displayed on the right side of the value.
  • symbol_padding string
    An empty string or the string (e.g. a whitespace character) to be used as the padding between the symbol and the value.
  • thousand_separator string
    An empty string or the character to use as the thousand separator.
  • decimal_separator string
    An empty string or the character to use as the decimal separator.
  • decimals integer
    The number of digits after the decimal separator. Note: For a currency that does use decimals, setting this to 0 can break payment add-on integrations where the payment gateway expects the currency to be using its standard number of decimals.

Examples

1. Update Euro

This example demonstrates how to change the EUR symbol to the left.

add_filter( 'gform_currencies', function( $currencies ) {
     $currencies['EUR']['symbol_left'] = '€';
     $currencies['EUR']['symbol_right'] = '';
     return $currencies;
 } );

Hint: use the HTML entity € instead of the symbol.

2. Add Indian Rupee

This example demonstrates how to add a new currency.

add_filter( 'gform_currencies', 'add_inr_currency' );
function add_inr_currency( $currencies ) {
    $currencies['INR'] = array(
        'name'               => __( 'India Rupee', 'gravityforms' ),
        'code'               => 'INR',
        'symbol_left'        => '₹',
        'symbol_right'       => '',
        'symbol_padding'     => ' ',
        'thousand_separator' => ',',
        'decimal_separator'  => '.',
        'decimals'           => 2
    );
 
    return $currencies;
}

Hint: use the HTML entity ₹ instead of the ₹ symbol.

3. Remove the space after the currency symbol for Pound Sterling

This example demonstrates how to remove the space after the £ for Pound Sterling.

add_filter( 'gform_currencies', function( $currencies ) {
	GFCommon::log_debug( 'gform_currencies: running.' );
	// Remove space after the currency symbol.
	$currencies['GBP']['symbol_padding'] = '';
	return $currencies;
} );

4. Remove decimals for USD

This example demonstrates how to remove the decimals. Remember that this is a global setting, so it will affect all your products. Important: Bear in mind that some payment gateways (e.g. Stripe) may require the amounts to include decimals, use this with caution and be sure to test it before adding it to production.

add_filter( 'gform_currencies', function( $currencies ) {
	GFCommon::log_debug( 'gform_currencies: running.' );
	// Set decimals allowed for USD to 0.
	$currencies['USD']['decimals'] = 0;
	return $currencies;
} );

Placement

This code can be used in the functions.php file of the active theme, a custom functions plugin, a custom add-on, or with a code snippets plugin.

See also the PHP section in this article: Where Do I Put This Code?

Source Code

This filter is located in RGCurrency::get_currencies() in currency.php.