: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* 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__( 'Canadian Dollar', '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__( 'Israeli New Sheqel', '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__( 'Russian Ruble', 'wpforms-lite' ),
'thousands_separator' => ' ',
'decimal_separator' => '.',
'name' => esc_html__( 'Singapore Dollar', 'wpforms-lite' ),
'thousands_separator' => ',',
'decimal_separator' => '.',
'name' => esc_html__( 'South African Rand', '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' => '.',
* 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 = '' ) { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh
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 any characters that are not a digit, a decimal point, or a minus sign.
* E is 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 = '' ) { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh
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 ) {
if ( is_string( $currency ) ) {
$currencies = wpforms_get_currencies();
$currency_code = strtoupper( $currency );
$currency = isset( $currencies[ $currency_code ] ) ? $currencies[ $currency_code ] : [];
* @param int $decimals Default number of decimals.
* @param array|string $currency Currency data we are getting decimals for.
return (int) apply_filters(
'wpforms_get_currency_decimals',
isset( $currency['decimals'] ) ? $currency['decimals'] : 2,
* If the currency not available anymore 'USD' used as default.
function wpforms_get_currency() {
$currency = wpforms_setting( 'currency' );
$currencies = wpforms_get_currencies();
* @param string $currency Payments currency.
* @param array $currencies Available currencies.
isset( $currencies[ $currency ] ) ? $currency : 'USD',
* Return recognized payment field types.
function wpforms_payment_fields() {
* Filters the recognized payment field types.
* @param array $fields Payment field types.
return (array) apply_filters(
'wpforms_payment_fields',
[ 'payment-single', 'payment-multiple', 'payment-checkbox', 'payment-select' ]
* Check if form or entry contains payment.
* @param string $type Either 'entry' or 'form'.
* @param array $data List of form fields.
function wpforms_has_payment( $type = 'entry', $data = [] ) {
$payment_fields = wpforms_payment_fields();
if ( ! empty( $data['fields'] ) ) {
foreach ( $data as $field ) {
if ( isset( $field['type'] ) && in_array( $field['type'], $payment_fields, true ) ) {