* Payment related functions.
* Get supported currencies.
function wpforms_get_currencies() {
'name' => esc_html__( 'U.S. Dollar', 'wpforms-lite' ),
'thousands_separator' => ',',
'decimal_separator' => '.',
'name' => esc_html__( 'Pound Sterling', 'wpforms-lite' ),
'thousands_separator' => ',',
'decimal_separator' => '.',
'name' => esc_html__( 'Euro', 'wpforms-lite' ),
'thousands_separator' => '.',
'decimal_separator' => ',',
'name' => esc_html__( 'Australian Dollar', 'wpforms-lite' ),
'thousands_separator' => ',',
'decimal_separator' => '.',
'name' => esc_html__( 'Brazilian Real', 'wpforms-lite' ),
'thousands_separator' => '.',
'decimal_separator' => ',',
'name' => esc_html__( 'Bulgarian Lev', 'wpforms-lite' ),
'thousands_separator' => ' ',
'decimal_separator' => ',',
'name' => esc_html__( 'Canadian Dollar', 'wpforms-lite' ),
'thousands_separator' => ',',
'decimal_separator' => '.',
'name' => esc_html__( 'Costa Rican Colón', 'wpforms-lite' ),
'thousands_separator' => ',',
'decimal_separator' => '.',
'name' => esc_html__( 'Central African CFA Franc', 'wpforms-lite' ),
'thousands_separator' => ',',
'decimal_separator' => '',
'name' => esc_html__( 'Czech Koruna', 'wpforms-lite' ),
'symbol' => 'Kč',
'thousands_separator' => '.',
'decimal_separator' => ',',
'name' => esc_html__( 'Danish Krone', 'wpforms-lite' ),
'thousands_separator' => '.',
'decimal_separator' => ',',
'name' => esc_html__( 'Hong Kong Dollar', 'wpforms-lite' ),
'thousands_separator' => ',',
'decimal_separator' => '.',
'name' => esc_html__( 'Hungarian Forint', 'wpforms-lite' ),
'thousands_separator' => '.',
'decimal_separator' => ',',
'name' => esc_html__( 'Indian Rupee', 'wpforms-lite' ),
'thousands_separator' => ',',
'decimal_separator' => '.',
'name' => esc_html__( 'Israeli New Sheqel', 'wpforms-lite' ),
'thousands_separator' => ',',
'decimal_separator' => '.',
'name' => esc_html__( 'Japanese Yen', 'wpforms-lite' ),
'thousands_separator' => ',',
'decimal_separator' => '',
'name' => esc_html__( 'Malaysian Ringgit', 'wpforms-lite' ),
'symbol' => 'RM',
'thousands_separator' => ',',
'decimal_separator' => '.',
'name' => esc_html__( 'Mexican Peso', 'wpforms-lite' ),
'thousands_separator' => ',',
'decimal_separator' => '.',
'name' => esc_html__( 'Norwegian Krone', 'wpforms-lite' ),
'thousands_separator' => '.',
'decimal_separator' => ',',
'name' => esc_html__( 'New Zealand Dollar', 'wpforms-lite' ),
'thousands_separator' => ',',
'decimal_separator' => '.',
'name' => esc_html__( 'Philippine Peso', 'wpforms-lite' ),
'thousands_separator' => ',',
'decimal_separator' => '.',
'name' => esc_html__( 'Polish Zloty', 'wpforms-lite' ),
'symbol' => 'zł',
'thousands_separator' => '.',
'decimal_separator' => ',',
'name' => esc_html__( 'Romanian Leu', 'wpforms-lite' ),
'thousands_separator' => ',',
'decimal_separator' => '.',
'name' => esc_html__( 'Russian Ruble', 'wpforms-lite' ),
'thousands_separator' => ' ',
'decimal_separator' => '.',
'name' => esc_html__( 'Saudi Arabian Riyal', 'wpforms-lite' ),
'thousands_separator' => ',',
'decimal_separator' => '.',
'name' => esc_html__( 'Singapore Dollar', 'wpforms-lite' ),
'thousands_separator' => ',',
'decimal_separator' => '.',
'name' => esc_html__( 'Serbian Dinar', 'wpforms-lite' ),
'thousands_separator' => ',',
'decimal_separator' => '.',
'name' => esc_html__( 'South African Rand', 'wpforms-lite' ),
'thousands_separator' => ',',
'decimal_separator' => '.',
'name' => esc_html__( 'South Korean Won', 'wpforms-lite' ),
'thousands_separator' => ',',
'decimal_separator' => '',
'name' => esc_html__( 'Sri Lankan Rupee', 'wpforms-lite' ),
'thousands_separator' => ',',
'decimal_separator' => '.',
'name' => esc_html__( 'Swedish Krona', 'wpforms-lite' ),
'thousands_separator' => '.',
'decimal_separator' => ',',
'name' => esc_html__( 'Swiss Franc', 'wpforms-lite' ),
'thousands_separator' => ',',
'decimal_separator' => '.',
'name' => esc_html__( 'Taiwan New Dollar', 'wpforms-lite' ),
'thousands_separator' => ',',
'decimal_separator' => '.',
'name' => esc_html__( 'Thai Baht', 'wpforms-lite' ),
'thousands_separator' => ',',
'decimal_separator' => '.',
'name' => esc_html__( 'Turkish Lira', 'wpforms-lite' ),
'thousands_separator' => ',',
'decimal_separator' => '.',
'name' => esc_html__( 'United Arab Emirates Dirham', 'wpforms-lite' ),
'symbol' => 'د.إ',
'thousands_separator' => ',',
'decimal_separator' => '.',
* Filter for currencies supported in WPForms payments.
* @param array $currencies List of currencies.
return array_change_key_case( (array) apply_filters( 'wpforms_currencies', $currencies ), CASE_UPPER );
* Sanitize amount by stripping out thousands separators.
* @link https://github.com/easydigitaldownloads/easy-digital-downloads/blob/master/includes/formatting.php#L24
* @param string $amount Price amount.
* @param string $currency Currency ISO code (USD, EUR, etc).
function wpforms_sanitize_amount( $amount, $currency = '' ) {
if ( empty( $currency ) ) {
$currency = wpforms_get_currency();
$currency = strtoupper( $currency );
$currencies = wpforms_get_currencies();
$thousands_sep = $currencies[ $currency ]['thousands_separator'] ?? ',';
$decimal_sep = $currencies[ $currency ]['decimal_separator'] ?? '.';
* Filter the raw price amount before sanitization.
* @param string $amount Raw price amount.
* @param string $currency Currency ISO code (USD, EUR, etc).
* @param string $thousands_sep Thousands separator.
* @param string $decimal_sep Decimal separator.
$amount = (string) apply_filters( 'wpforms_sanitize_amount_before', $amount, $currency, $thousands_sep, $decimal_sep );
if ( $decimal_sep === ',' && strpos( $amount, $decimal_sep ) !== false ) {
if ( ( $thousands_sep === '.' || $thousands_sep === ' ' ) && strpos( $amount, $thousands_sep ) !== false ) {
$amount = str_replace( $thousands_sep, '', $amount );
} elseif ( empty( $thousands_sep ) && strpos( $amount, '.' ) !== false ) {
$amount = str_replace( '.', '', $amount );
$amount = str_replace( $decimal_sep, '.', $amount );
} elseif ( $thousands_sep === ',' && strpos( $amount, $thousands_sep ) !== false ) {
$amount = str_replace( $thousands_sep, '', $amount );
// Remove current symbol.
$amount = str_replace( $currencies[ $currency ]['symbol'], '', $amount );
* Remove any characters that are not a digit, a decimal point, or a minus sign.
* E is an exponent notation. Float number can be written in the form 2E-13, which means 2 * 10^-13.
$sanitized_amount = (string) preg_replace( '/[^E0-9.-]/', '', $amount );
* Set correct currency decimals.
* @param int $decimals Default number of decimals.
* @param string $sanitized_amount Price amount.
$decimals = (int) apply_filters(
'wpforms_sanitize_amount_decimals',
wpforms_get_currency_decimals( $currency ),
* Filter the sanitized amount.
* @param string $sanitized_amount Sanitized price amount.
* @param string $raw_amount Raw price amount.
* @param string $currency Currency ISO code (USD, EUR, etc).
* @param int $decimals Number of decimals.
return (string) apply_filters(
'wpforms_sanitize_amount',
number_format( (float) $sanitized_amount, $decimals, '.', '' ),
* Return a nicely formatted amount.
* @param string $amount Price amount.
* @param bool $symbol Currency symbol ($, €).
* @param string $currency Currency ISO code (USD, EUR, etc).
* @return string $amount Newly formatted amount or Price Not Available
function wpforms_format_amount( $amount, $symbol = false, $currency = '' ) {
if ( empty( $currency ) ) {
$currency = wpforms_get_currency();
$currency = strtoupper( $currency );
$currencies = wpforms_get_currencies();
$thousands_sep = isset( $currencies[ $currency ]['thousands_separator'] ) ? $currencies[ $currency ]['thousands_separator'] : ',';
$decimal_sep = isset( $currencies[ $currency ]['decimal_separator'] ) ? $currencies[ $currency ]['decimal_separator'] : '.';
$sep_found = ! empty( $decimal_sep ) ? strpos( $amount, $decimal_sep ) : false;
$whole = substr( $amount, 0, $sep_found );
$part = substr( $amount, $sep_found + 1, ( strlen( $amount ) - 1 ) );
$amount = $whole . '.' . $part;
// Strip "," (comma) from the amount (if set as the thousands' separator).
$thousands_sep === ',' &&
strpos( $amount, $thousands_sep ) !== false
$amount = (float) str_replace( ',', '', $amount );
if ( empty( $amount ) ) {
/** This filter is documented in wpforms_sanitize_amount function above. */
$decimals = (int) apply_filters(
'wpforms_sanitize_amount_decimals',
wpforms_get_currency_decimals( $currency ),
$number = number_format( (float) $amount, $decimals, $decimal_sep, $thousands_sep );
// Display a symbol, if any.
if ( $symbol && isset( $currencies[ $currency ]['symbol_pos'] ) ) {
* Filter for currency symbol padding.
* @param string $symbol_padding Currency symbol padding.
$symbol_padding = apply_filters( 'wpforms_currency_symbol_padding', ' ' );
if ( $currencies[ $currency ]['symbol_pos'] === 'right' ) {
$number .= $symbol_padding . $currencies[ $currency ]['symbol'];
$number = $currencies[ $currency ]['symbol'] . $number;
* Get default number of decimals for a given currency.
* If not provided inside the currency, default value is used, which is 2.
* @param array|string $currency Currency data we are getting decimals for.
function wpforms_get_currency_decimals( $currency ) {