WPCS - WordPress Currency Switcher Professional

WordPress currency switcher price format: code, symbol, separators

The WordPress currency switcher price format is set in a few places: the symbol, its position, the cents, decimals and separators are chosen per currency, while the custom price format with the currency code applies to all of them. Knowing which setting builds which part of the price lets you get $751.45 (CAD), 1.250,00 € or a price without a symbol without guessing. Changing the amount itself (rounding to 10 or to .99) is a different task, covered in how to round converted prices.

How WPCS builds a price

Each [wpcs_price] shortcode is printed in four steps:

  1. The converted number is formatted with the cents, Decimals and Format settings of the current currency: 751.45.
  2. The currency symbol is put on the left or right of the number, as set in its Symbol pos.: $751.45.
  3. The Custom price format option, if filled, wraps the result and can add the currency code: $751.45 (CAD).
  4. Everything is wrapped in HTML with two CSS classes, and the wpcs_price_html_tail filter can add more before the closing tag.
<span class="wpcs_price" id="wpcs_..." data-amount="544.53"><span class="wpcs_price_symbol">$</span>751.45 (CAD)</span>

The settings live in two places in Settings → Currency Switcher:

SettingWhereApplies to
Symbol, Symbol pos.Currency row, Currencies tabThat currency
Show cents / Hide cents, DecimalsCurrency rowThat currency
Format (separators)Currency rowThat currency
Decimal separator, Thousandth separatorOptions tabCurrencies whose Format is default
Custom money signs.Options tabAdds symbols to the symbol list
Custom price formatOptions tabEvery price in every currency

Symbol and symbol position per currency

The symbol is a drop-down in each currency row. If your sign is not in the list (KSh, S/, GH₵), type it into Custom money signs. on the Options tab, separated by commas, press Save options, and it appears in the symbol list of every row. Developers can extend the list with the wpcs_currency_symbols filter.

The position selector next to it has four values:

  • left: $99.00
  • right: 99.00$
  • left space: $ 99.00
  • right space: 99.00 €

The space is a non-breaking space, so the symbol never wraps to the next line without its number.

Show the currency code after the price

The Custom price format option on the Options tab accepts two keys: __PRICE__ is the number together with its symbol (already positioned), __CODE__ is the code of the currency being shown. Leave the field empty for the default format.

Custom price formatResult
__PRICE__ (__CODE__)$751.45 (CAD)
__CODE__ __PRICE__CAD $751.45
__PRICE__ __CODE__, symbol hidden with CSS751.45 CAD

This is the right tool when several currencies share a symbol, such as USD, CAD and AUD. It applies to every price of the site, fixed prices included, and cannot be limited to some pages in the settings. To add the code to a few prices only, use the shortcode attribute shown in the section on text after the price.

Decimal and thousands separators per currency

Each currency row has a Format selector: default, 1,000.00, 1.000,00, 1 000,00, 1 000.00, 1000,00 and 1000.00. So USD can be shown as 1,250.00, EUR as 1.250,00 and CHF as 1 250.00 on the same site. A currency set to default uses the global Decimal separator and Thousandth separator from the Options tab (a dot and a comma unless you change them). Older forum answers say that separators can only be set for all currencies at once; the per-currency Format selector replaced that limit.

The number of decimals is set per currency as well:

  • Decimals: 0 to Decimals: 8 sets the number of decimals, for example 3 for prices like 0.084. It works only while the row is set to Show cents.
  • Hide cents prints whole numbers, whatever Decimals says.
  • JPY and TWD are always printed without cents.

These settings only change the display. The value you write in [wpcs_price value=1250.50] always uses a dot for decimals and no thousands separator, whatever format the currencies use.

A price without the symbol, or the symbol alone

[wpcs_price] has no attribute to drop the symbol, but the symbol sits in its own element, so CSS can hide it. For every price, or only inside one block of your page:

/* Appearance → Customize → Additional CSS */
.wpcs_price_symbol { display: none; }

/* or only inside an element with the class pricing-table */
.pricing-table .wpcs_price_symbol { display: none; }

Set the symbol position to left or right for those currencies, otherwise the non-breaking space stays in front of the number.

When you need the bare number or the bare symbol as text, for a form field, a data attribute or a script, register two small shortcodes. They use $WPCS->price(), which converts and formats the amount (your rounding filter included), and $WPCS->get_currencies() for the symbol:

/*
 * [my_price_number value=100] prints the converted number, e.g. 86.00
 * [my_currency_symbol]        prints the symbol of the current currency
 * Child theme functions.php or a code snippets plugin.
 */
add_shortcode('my_price_number', function ($atts) {
    global $WPCS;
    $atts = shortcode_atts(array('value' => 0), $atts);
    if (empty($WPCS)) {
        return '';
    }
    return esc_html($WPCS->price(floatval($atts['value'])));
});

add_shortcode('my_currency_symbol', function () {
    global $WPCS;
    if (empty($WPCS)) {
        return '';
    }
    $currencies = $WPCS->get_currencies();
    $code = $WPCS->current_currency;
    return isset($currencies[$code]) ? wp_kses_post($currencies[$code]['symbol']) : '';
});

Both are printed when the page is built. With I am using cache plugin on my site set to Yes, the plugin redraws only the .wpcs_price elements after loading, so on a cached page these two keep the currency of the cached copy.

Add text after the price

After every price in one currency

The wpcs_price_html_tail filter adds HTML inside the price element. It runs for every price, so check the currency:

/*
 * WPCS: add a note after every price shown in USD.
 * Child theme functions.php or a code snippets plugin.
 */
add_filter('wpcs_price_html_tail', function ($price_html) {
    global $WPCS;
    if (!empty($WPCS) && $WPCS->current_currency === 'USD') {
        $price_html .= ' <span class="my-price-note">excl. VAT</span>';
    }
    return $price_html;
});

Because the text is part of the price element, it is also redrawn correctly on cached pages.

After selected prices only

WPCS passes every attribute of [wpcs_price], including ones it does not use itself, to the wpcs_shortcode_price_html_manipulation filter, together with the currency being shown. That makes your own attributes possible:

[wpcs_price value=544.53 after=" ({code})"]          → $751.45 (CAD)
[wpcs_price value=1.99 after="/yr" after_for="USD"]  → $1.99/yr, only in USD
/*
 * WPCS: [wpcs_price ... after="text"] adds text after this price only.
 * {code} is replaced by the currency code; after_for="USD,CAD" limits it to these currencies.
 * Child theme functions.php or a code snippets plugin.
 */
add_filter('wpcs_shortcode_price_html_manipulation', function ($price_html, $atts, $currency) {
    if (!is_array($atts) || !isset($atts['after']) || $atts['after'] === '') {
        return $price_html;
    }
    if (!empty($atts['after_for'])) {
        $codes = array_map('trim', explode(',', strtoupper($atts['after_for'])));
        if (!in_array($currency, $codes, true)) {
            return $price_html;
        }
    }
    $text = str_replace('{code}', $currency, $atts['after']);
    return $price_html . '<span class="my-price-after">' . esc_html($text) . '</span>';
}, 10, 3);

The text is placed after the price element, and the AJAX redraw for cached sites does not run this filter: on a cached page it stays as it was when the page was cached. For whole sentences or blocks that depend on the currency, see showing content for the selected currency.

Style the price with CSS

Use .wpcs_price for the whole price and .wpcs_price_symbol for the symbol; the FAQ shows how to make the price bold. The decimals have no element of their own. To style them, for example smaller and raised, wrap them with the tail filter:

/*
 * WPCS: wrap the decimal part of every price in <span class="my-price-decimals">.
 * Child theme functions.php or a code snippets plugin.
 */
add_filter('wpcs_price_html_tail', function ($price_html) {
    global $WPCS;
    if (empty($WPCS)) {
        return $price_html;
    }
    $sep = $WPCS->get_decimal_separator($WPCS->current_currency);
    if ($sep === '') {
        return $price_html;
    }
    // The separator and the digits after it, outside HTML attributes.
    return preg_replace(
        '/(\d)' . preg_quote($sep, '/') . '(\d+)(?![^<]*>)/',
        '$1<span class="my-price-decimals">' . $sep . '$2</span>',
        $price_html,
        1
    );
});
/* Additional CSS */
.my-price-decimals { font-size: 0.6em; vertical-align: super; }

Prices without cents are left unchanged. To show one amount in several currencies side by side, use the fix_currency attribute, described in showing prices in multiple currencies.

If the format does not change

  • Press Save options after editing a currency row; the row settings are saved with the page, not instantly.
  • A currency on Format: default follows the global separators on the Options tab, so changing the global ones changes only those currencies.
  • Decimals has no effect while the row is on Hide cents, and none at all for JPY and TWD.
  • Clear the page cache and check in a private window: cached pages keep the old format.

If a price still looks wrong, post the shortcode and a screenshot of the currency row on the WPCS support forum.