Contents
Switch Shopper Currency - Plugixa Multi Currency for WooCommerce
POST /plugixa-multi-currency/v1/public/switch
Set the visitor’s currency, as a switcher does: it remembers the choice in the visitor’s cookie and recalculates their cart. Use it to build your own switcher. See Currency switcher.
Public: no sign-in. The route protects itself instead, as described below. Each address can switch 120 times an hour.
Request
POST https://your-store.example/wp-json/plugixa-multi-currency/v1/public/switch
Request body
Content type: application/json
| Field | Type | Required | Description |
|---|---|---|---|
currency |
string |
Yes | The code of an enabled currency. |
{
"currency": "EUR"
}
Responses
200 OK.
{
"success": true,
"data": {
"currency": "EUR"
}
}
The response sets the currency cookie and is sent with Cache-Control: no-store, private. Call it from the shopper’s browser on your site, so the cookie lands there: a call from your server changes nothing for the shopper. Reload the page afterwards to show the new prices. With Pro, the switch is counted in Currency statistics.
Errors
| Status | Code | When |
|---|---|---|
400 |
plugixa_multi_currency_unknown_currency |
The currency is not in your list or is off: This currency is not available. |
429 |
plugixa_multi_currency_rate_limited |
Too many requests from this address: Too many requests. Please wait a little while and try again. |
403 |
plugixa_multi_currency_captcha_failed |
A CAPTCHA check added with the plugixa_multi_currency_public_request_captcha filter refused the request. |
Plus the errors every endpoint can return.
Examples
curl -s -X POST "https://your-store.example/wp-json/plugixa-multi-currency/v1/public/switch" \
-H "Content-Type: application/json" \
-d '{"currency":"EUR"}'
<?php
$ch = curl_init('https://your-store.example/wp-json/plugixa-multi-currency/v1/public/switch');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
CURLOPT_POSTFIELDS => json_encode([
'currency' => 'EUR',
]),
]);
$response = json_decode(curl_exec($ch), true);
curl_close($ch);
const response = await fetch('https://your-store.example/wp-json/plugixa-multi-currency/v1/public/switch', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ currency: 'EUR' }),
});
await response.json();
location.reload(); // show the page in the new currency
Quick Links
Share