Contents
On this page

Convert Amount - Plugixa Multi Currency for WooCommerce

GET /plugixa-multi-currency/v1/convert

Convert an amount the way the shop would, with the currency’s rate, margin and rounding, and Pro charm pricing. Nothing is saved. See Margins and rounding.

Needs a user with the plugixa_multi_currency_view capability (signed in with an Application Password, or the login cookie with an X-WP-Nonce header). Administrators hold it; see Capabilities.

Request

GET https://your-store.example/wp-json/plugixa-multi-currency/v1/convert?amount=49.90&to=EUR

Query parameters

Field Type Required Description
amount string Yes The amount in your store currency, with a dot for decimals, for example 49.90.
to string Yes The code of a currency in your list, or the store currency.
context string No price (default), shipping, fee or raw. It picks the rounding rule. The fixed amount of the margin is only added to a price. raw applies the rate and margin percent with no rounding rule, the way coupon amounts and spend limits are converted.

Responses

200 OK.

{
  "success": true,
  "data": {
    "amount": "49.90",
    "from": "USD",
    "to": "EUR",
    "exact": "45.8589626898127",
    "converted": "45.86"
  }
}
Field Type Meaning
amount string The amount you sent
from string Your store currency
to string The target currency
exact string amount × rate × (1 + margin %), plus the fixed amount for a price, before rounding
converted string What the shop shows and charges, with the currency’s decimals

Here 49.90 × 0.9099181073 × 1.01 = 45.8589…, shown as 45.86 €. Converting 49.90 to JPY with context=shipping gives exact 7916.346678798 and converted 7916: in this store the yen has no shipping rounding step, while its price rule rounds up to the next 10.

Errors

Status Code When
401 / 403 plugixa_multi_currency_forbidden The caller lacks the capability.
400 plugixa_multi_currency_unknown_currency to is not in your list: This currency is not in your list.

Plus the errors every endpoint can return.

Examples

curl -s "https://your-store.example/wp-json/plugixa-multi-currency/v1/convert?amount=49.90&to=EUR" \
  -u "$WP_USER:$WP_APP_PASSWORD"
<?php
$ch = curl_init('https://your-store.example/wp-json/plugixa-multi-currency/v1/convert?amount=49.90&to=EUR');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_USERPWD        => getenv('WP_USER') . ':' . getenv('WP_APP_PASSWORD'),
]);
$response = json_decode(curl_exec($ch), true);
curl_close($ch);
const response = await fetch('https://your-store.example/wp-json/plugixa-multi-currency/v1/convert?amount=49.90&to=EUR', {
  headers: {
    'Authorization': `Basic ${btoa(`${process.env.WP_USER}:${process.env.WP_APP_PASSWORD}`)}`,
  },
});
const { data } = await response.json();

Quick Links

Share