Several currencies in WooCommerce: what a small plugin can do and where it stops
A shop that sells abroad wants prices in the visitor’s currency. WooCommerce has one store currency, and multi-currency plugins do a lot of work behind the scenes: converting prices, rounding them, charging the right currency through the payment gateway, and keeping reports consistent. A small custom solution can cover one common case, showing and charging prices in a second currency with a fixed rate per currency, if the payment gateway supports those currencies. Everything else is a reason to use a maintained plugin.
Problem: A Polish shop with prices in PLN wants visitors from the euro area to see and pay prices in EUR. Live exchange rates are not wanted: the shop sets a rate once a month and rounds prices to .99.
Solution: Store the chosen currency in the WooCommerce session (set by a switcher or by country), change the currency with the woocommerce_currency filter, convert prices with the price filters using a rate from the options, round them consistently, and make sure the cart is recalculated when the currency changes. Keep reports in mind: orders store their own currency.
The chosen currency
const HA_CURRENCIES = array( 'PLN' => 1.0, 'EUR' => 0.2350 ); // rate relative to the store currency
function ha_currency(): string {
if ( ! function_exists( 'WC' ) || ! WC()->session ) {
return 'PLN';
}
$chosen = (string) WC()->session->get( 'ha_currency', '' );
return isset( HA_CURRENCIES[ $chosen ] ) ? $chosen : 'PLN';
}
add_action( 'template_redirect', function (): void {
if ( isset( $_GET['currency'] ) && WC()->session ) {
$requested = strtoupper( sanitize_key( wp_unslash( $_GET['currency'] ) ) );
if ( isset( HA_CURRENCIES[ $requested ] ) ) {
WC()->session->set_customer_session_cookie( true );
WC()->session->set( 'ha_currency', $requested );
WC()->cart && WC()->cart->calculate_totals();
}
}
} );
add_filter( 'woocommerce_currency', fn( $currency ) => is_admin() && ! wp_doing_ajax() ? $currency : ha_currency() );
The currency is a per-visitor choice stored in the session, so it survives page loads and is used at checkout. In the admin, the store currency stays, so product edit screens always show base prices.
Convert prices
function ha_convert_price( $price ) {
if ( '' === $price || null === $price || 'PLN' === ha_currency() ) {
return $price;
}
$converted = (float) $price * HA_CURRENCIES[ ha_currency() ];
return (string) ( floor( $converted ) + 0.99 ); // psychological rounding
}
foreach ( array( 'woocommerce_product_get_price', 'woocommerce_product_get_regular_price', 'woocommerce_product_get_sale_price',
'woocommerce_product_variation_get_price', 'woocommerce_product_variation_get_regular_price', 'woocommerce_product_variation_get_sale_price' ) as $hook ) {
add_filter( $hook, 'ha_convert_price', 20 );
}
add_filter( 'woocommerce_get_variation_prices_hash', function ( array $hash ): array {
$hash[] = ha_currency();
return $hash;
} );
All price getters are filtered, so catalog, cart and order use the converted values consistently. The variation hash includes the currency because WooCommerce caches price ranges of variable products. Shipping costs, fees and coupons with fixed amounts need the same conversion through their own filters (for example woocommerce_package_rates for shipping rates); this is where small solutions usually start to miss cases.
Payment, caching and reports
- Gateway: the order is created in EUR, and the gateway must accept EUR for this account. Stripe and PayPal support many currencies; local gateways often do not.
- Page cache: pages with prices differ per currency. A full-page cache must vary by the currency cookie or be bypassed for shop pages: Nginx FastCGI cache.
- Reports: each order stores its currency, and WooCommerce Analytics sums amounts without converting them. Revenue reports across currencies need their own conversion.
Role-based price changes use the same filters: tiered and role-based prices.
NOTE: Automatic currency by country (geolocation) is possible with WC_Geolocation::geolocate_ip(), but should only preselect the currency, not lock it: travelers and VPN users must be able to switch. With more than two currencies, live rates, per-currency prices entered by hand, or currency-specific coupons, a maintained multi-currency plugin is the safer choice.