Fixed price per currency in WordPress with [wpcs_price type=fixed]
A fixed price per currency in WordPress means that you choose the amount for every currency yourself: 15 in US dollars, 20 in euros, 45 in pounds, with no exchange rate involved. WPCS does this with the type=fixed attribute of the [wpcs_price] shortcode. The syntax is strict, and when one character is off, the price shows the word none or 0.00 instead of an amount. Below are the exact syntax, what each symptom means, and how to control cents on fixed prices.
Converted prices and fixed prices
A normal [wpcs_price value=100] reads 100 as an amount in your base currency and multiplies it by the exchange rate of the currency the visitor has selected. The amount follows the rates, so it changes whenever they are updated.
With type=fixed, nothing is converted. The plugin splits value at every comma into CODE:amount pairs, picks the pair whose code is the visitor's currency, and prints that amount with the symbol, decimals and number format of that currency:
[wpcs_price value=100]
[wpcs_price type=fixed value=USD:15,EUR:20,GBP:45]
A visitor who selected EUR sees 20 euros from the second shortcode, whatever the rate is today. Use fixed prices for amounts that must not move with the rates: rounded market prices (19 instead of 18.37), price lists agreed per country, membership plans and service packages.
Fixed price per currency: the syntax rules
The pairs are cut apart with plain string splitting, so every character counts.
| Write | Not | What the wrong form does |
|---|---|---|
USD:15,EUR:20 | USD:15, EUR:20 | The space becomes part of the code (" EUR"), so EUR shows none |
EUR:20 | eur:20 or Euro:20 | Codes must be the currency codes from the Currencies tab, in capital letters: otherwise none |
EUR:1250.50 | EUR:1250,50 | The comma starts a new pair: 1250.00 is shown and the cents are lost |
EUR:1250 | EUR:1,250 or EUR:1.250 | Thousands separators break the number: 1.00 or 1.25 is shown |
EUR:20 | EUR:€20 | A symbol in front of the number is read as 0: 0.00 |
value=USD:15,EUR:20 | value=”USD:15,EUR:20” | The curly quote sticks to the first code: the first currency shows none |
A fixed value contains no spaces, so it needs no quotes at all. Writing [wpcs_price type=fixed value=USD:15,EUR:20,GBP:45] without any quotes removes the most frequent error completely.
Why the fixed price shows "none" or 0
Each symptom points to one cause:
| What you see | Cause | Fix |
|---|---|---|
| Every currency shows 0 or 0.00 | type is not read as fixed. With type=”fixed”, WordPress does not recognise the curly marks as quotes and keeps them in the value, so the shortcode treats the price as a normal one and tries to convert a text that is not a number. | Write type=fixed |
The first currency of the list shows none, the others work | A quote character became part of value, so the first code reads ”INR instead of INR. Curly quotes do this, and so do some page builder elements and table plugins that pass quotes on as characters. | Remove the quotes around value |
One currency shows none | The currency is missing from the list (typically a currency added after the shortcode was written), or its code differs from the Currencies tab | Add the pair or correct the code |
Every currency shows none | value ended up empty. Most often the pairs were put into meta_value, which expects the name of a custom field, not prices | Use value= for pairs written in the shortcode |
| The price and the switcher show different currencies | A page cache or the browser cache served a page built for another currency | See below |
Curly quotes (” “) arrive with copy and paste: from a web page, a document, an email or a chat, or from an app that replaces straight quotes as you type. If you are not sure what is in the editor, delete the quotes and type the shortcode again by hand.
For the last row: after changing currencies or settings, clear the cache of your cache plugin and the browser (Ctrl+F5) and test again. If visitors keep getting prices in the wrong currency on a cached site, set up the plugin for caching as described in currency switcher and cache plugins.
Every currency needs its own amount
A fixed shortcode cannot mix fixed and converted currencies. A currency without a pair is not calculated from the other amounts; it shows none. So when you add a currency on the Currencies tab, every fixed price on the site needs a new pair. To find them, type type=fixed into the search field of the Posts and Pages lists in the admin (the search looks into the content), then check widgets and page builder templates separately.
If what you really need is one price written in a currency other than the base and converted for everybody else, that is a different technique: see how the base currency works, which includes a small shortcode for prices entered in any currency.
Fixed prices stored in a custom field
The pairs can live in a custom field instead of the shortcode. Put the same text into the field, for example USD:15,EUR:20,GBP:45, and name the field in meta_value:
[wpcs_price meta_value=plan_prices type=fixed]
meta_value takes the meta key of the field of the current post (add post_id=123 for another post), and the same syntax rules apply to the text in the field. Finding the right key, especially for ACF fields, is explained in converting an ACF price field.
Cents, decimals and rounding on fixed prices
A fixed amount is printed with the settings of its currency's row on the Currencies tab: Show cents or Hide cents, Decimals and Format. With two decimals, USD:50 is shown as 50.00. These settings apply to every price in that currency, converted or fixed.
Fixed prices do not pass through the wpcs_price filter, so rounding code hooked there changes converted prices only. That is by design: a fixed amount is shown as you wrote it.
To show some fixed prices without cents and others with them (a plan at 50 and add-ons at 1.15 on the same page), give the shortcodes that should lose their cents an extra attribute, for example name=no-cents. WPCS ignores unknown attributes, but it passes all of them to the wpcs_shortcode_price_html_manipulation filter together with the price HTML and the current currency:
[wpcs_price type=fixed value=USD:50,EUR:45,GBP:40 name=no-cents]
[wpcs_price type=fixed value=USD:1.15,EUR:1.05,GBP:0.95]
/*
* WPCS: remove the decimal part from [wpcs_price ... name=no-cents].
* Child theme functions.php or a code snippets plugin.
*/
add_filter('wpcs_shortcode_price_html_manipulation', function ($price_html, $atts, $currency) {
global $WPCS;
if (is_array($atts) && isset($atts['name']) && $atts['name'] === 'no-cents') {
// decimal separator of this currency, from its Format setting
$sep = preg_quote($WPCS->get_decimal_separator($currency), '/');
// drop the separator and the digits after it, outside HTML attributes
$price_html = preg_replace('/(\d)' . $sep . '\d+(?![^<]*>)/', '$1', $price_html);
}
return $price_html;
}, 10, 3);
The filter works on converted prices too. One limit: when I am using cache plugin on my site is set to Yes on the Options tab, the plugin redraws every price with AJAX after the page loads, and that redraw does not run this filter. On such a site, use Hide cents or Decimals on the currency instead.
Checklist
- The shortcode is
[wpcs_price type=fixed value=...]with no quotes, or straight ones only. - Every currency of the Currencies tab has a pair, with its code in capital letters.
- No spaces, no symbols, no thousands separators, a dot for decimals.
- Pairs written in the shortcode go into
value;meta_valueholds only a field name. - Caches cleared after changes, and the page tested in a private window.
If a fixed price still shows none after these checks, open a topic on the WPCS support forum with the exact shortcode, the currency codes from your Currencies tab and a link to the page.