Exchange rate text shortcode
The exchange rate shortcode prints one short line of text with a live rate, such as 1 USD = 0.3087 KWD. Use it in a product description, an FAQ, a shipping page or a banner to show shoppers the rate your store uses. For example, a store that sells in US dollars can tell shoppers in Kuwait “Today: 1 USD = 0.3087 KWD” right next to its prices.
How it works#
The shortcode takes the exchange rates your store already uses, works out the rate between two currencies and drops it into a line of text. It always uses the latest rates your store has, so you never edit the number by hand. (A cached copy of a page keeps the rates from when it was cached.) It does not add buttons, boxes or styling: it is plain text that takes the look of the text around it.
If you leave out the to currency, the line follows each visitor. A shopper using KWD sees the rate in KWD, and a shopper using EUR sees it in EUR.
Add it to a page#
This is the basic shortcode:
[wccs_rate]
- Edit the page, post or widget where you want the line.
- Paste the shortcode where the text should appear. It works inside a paragraph too.
- Add any attributes you need from the table below.
- Save and view the page.
Attributes#
| Attribute | Default | What it does |
|---|---|---|
from |
USD |
The currency on the left, the “1” side |
to |
the visitor’s current currency | The currency on the right |
decimals |
4 |
Decimal places in the rate, from 0 to 8. Values outside this range are brought back into it. |
template |
1 {from} = {rate} {to} |
The text of the line. Use the placeholders {from}, {rate} and {to} anywhere in your own wording. |
Examples#
The rate in the visitor’s own currency, with the default wording:
[wccs_rate]
A Kuwait shopper sees 1 USD = 0.3087 KWD. A shopper using USD sees 1 USD = 1.0000 USD.
A fixed pair with your own wording and 2 decimals:
[wccs_rate from="USD" to="AED" decimals="2" template="Today: 1 {from} buys {rate} {to}"]
This prints, for example, Today: 1 USD buys 3.67 AED.
The rate the other way round, from dinar to dollar:
[wccs_rate from="KWD" to="USD"]
The maths. Rates are stored against the US dollar, and the shortcode divides one by the other. With an example rate of 1 USD = 0.3087 KWD, the KWD to USD rate is 1 / 0.3087 = 3.23939…, which shows as 1 KWD = 3.2394 USD with 4 decimals.
Good to know#
- Cached pages show the right currency. When
tois left out, a cached page carries the line for every enabled currency, and the visitor’s browser shows the one for their currency. In Instant switching mode (beta), the line also changes as soon as the shopper switches. - Plain exchange rate only. The rate does not include your conversion fees or rounding, and it does not use fixed exchange rates from the Pricing tab. It can therefore differ a little from the converted prices in your shop.
- Number format. The rate always uses a full stop for decimals and a comma for thousands, whatever you set on the Pricing tab.
- Nothing shows? The shortcode prints nothing when either currency has no rate. Check the currency codes (three letters, such as
EUR) and that your rate provider returns a rate for both. - Plain text template. HTML tags in
templateare removed. To make the line bold or coloured, wrap the shortcode in your own formatting, or style thewccs-rateclass with CSS.
Related docs#
- Currency converter shortcode
- Choosing an exchange rate provider
- Fixed exchange rates
- How WC Currency Switch works with page caching