Frontend API

Methods to format money, and handle currency selection and conversion when multi-currency is enabled.

Returns a formatted string based on store currency settings.

This method will automatically use the store's base currency settings by default, or the selected currency in a multi-currency setup.

Format currency
swell.currency.format(10) // => $10.00

Optionally override default currency settings:

Override default currency settings
swell.currency.format(10, {
  code: 'EUR',
  locale: 'en-GB'
  decimals: 4, // number of decimal digits
  rate: 0.8874 // conversion rate
}) // => €8.874

Returns an array of enabled currencies. Result will be empty if multi-currency has not been configured on the store.

List enabled currencies
await swell.currency.list()

Sets a browser cookie and updates the user's session and cart to the selected currency.

In a multi-currency setup, call the select() method to change settings used by format() to render money values.

If a cart exists in the user's session, this method also updates the cart to reflect the user's currency preference.

Select a currency
await swell.currency.select('EUR')

Returns the selected currency code. Defaults to the store's base currency.

Get the slected currency
swell.currency.selected() // => USD

In a multi-currency setup, format() will automatically consider selected currency options. Formatting with a display currency will cause a money value to be converted using a standard conversion rate which is updated daily.

Multi-currency formatting
swell.currency.format(10) // => $10.00

await swell.currency.select('EUR')

swell.currency.format(10) // => €8.874

See our help center for more details on multi-currency setup.