WooCommerce Multi-Currency Setup Without Plugins: Custom Hooks and Geolocation GeoIP Code

Avoid heavy, slow plugins. Discover how to use custom hooks and WooCommerce GeoIP configurations to dynamically show localized currencies based on visitor location.

WooCommerce Multi-Currency Setup Without Plugins: Custom Hooks and Geolocation GeoIP Code

For WooCommerce store owners seeking to scale globally, showing localized prices increases add-to-cart rates and minimizes checkout friction. However, standard multi-currency plugins often inject bloated database queries, load heavy external script tags, and slow down page speeds.

If you only need to serve a few target regions—for example, showing USD to global visitors and LKR to visitors in Sri Lanka—you can implement a lightweight multi-currency system using custom code and WooCommerce's built-in Geolocation (GeoIP) integration.

This guide details how to configure GeoIP currency mapping, dynamic price conversion hooks, and custom checkout handlers using native WooCommerce filters.


1. Setting Up WooCommerce Geolocation (GeoIP)

WooCommerce has a built-in GeoIP lookup engine that resolves user locations based on their IP address without calling slow external APIs on every click.

Configuration Steps:

1. Go to WooCommerce > Settings > General.

2. Locate Default Customer Location and select Geolocate or Geolocate (with page caching support).

3. If using page caching, WooCommerce appends a query parameter (?v=...) to prevent browser cache engines from serving incorrect currency layouts to different regions.

4. Set up your MaxMind license key under WooCommerce > Settings > Integration to keep your GeoIP database updated.


2. Dynamic Currency Selector Hook

Once Geolocation is active, you can intercept the currency displayed on the frontend based on the user's country code. Add the following filter code to your theme's functions.php or a custom helper plugin:

`php

add_filter( 'woocommerce_currency', 'custom_geoip_currency_filter' );

function custom_geoip_currency_filter( $currency ) {

// Avoid changing currency in admin dashboards

if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {

return $currency;

}

// Initialize WooCommerce Geolocation class

if ( class_exists( 'WC_Geolite' ) || class_exists( 'WC_Geolocation' ) ) {

$location = WC_Geolocation::geolocate_ip();

$country = isset( $location['country'] ) ? $location['country'] : '';

switch ( $country ) {

case 'LK': // Sri Lanka

return 'LKR';

case 'GB': // United Kingdom

return 'GBP';

case 'EU': // European Union countries

case 'DE':

case 'FR':

return 'EUR';

default: // Global Fallback

return 'USD';

}

}

return $currency;

}

`


3. Localizing Prices (Applying Exchange Rates)

Now that the site currency updates based on location, you need to apply matching exchange rates to your catalog prices.

WooCommerce provides the woocommerce_product_get_price filter, which allows you to modify product prices on-the-fly. This prevents database bloat because you do not have to write separate product prices for every currency in your database.

`php

// Apply exchange rate calculations to frontend catalog prices

add_filter( 'woocommerce_product_get_price', 'custom_currency_conversion_handler', 10, 2 );

add_filter( 'woocommerce_product_get_regular_price', 'custom_currency_conversion_handler', 10, 2 );

function custom_currency_conversion_handler( $price, $product ) {

if ( ! $price ) return $price;

$current_currency = get_woocommerce_currency();

// Define exchange rate margins (relative to your default base currency, e.g. USD)

$rates = array(

'LKR' => 300.00, // 1 USD = 300 LKR

'GBP' => 0.78, // 1 USD = 0.78 GBP

'EUR' => 0.92 // 1 USD = 0.92 EUR

);

if ( isset( $rates[$current_currency] ) ) {

return (float) $price * $rates[$current_currency];

}

return $price;

}

`

*(Note: In a production setup, you can replace the hardcoded $rates array with an transient cache fetching live rates daily from an external exchange rate API.)*


4. Resolving Stripe & Payment Gateway Conversions

When localized prices are processed during checkout, payment gateways must charge the customer in the matching currency.

If you are using gateways like Stripe, verify that the gateway plugin supports multi-currency options. For gateways that only accept a single base currency (like LKR-only local Sri Lankan processors), you can use custom hooks to convert the checkout total back to the gateway's accepted currency before submission:

`php

add_filter( 'woocommerce_paypal_express_checkout_request_params', 'convert_checkout_currency_for_gateway' );

function convert_checkout_currency_for_gateway( $params ) {

$current_currency = get_woocommerce_currency();

// If user checked out in USD but gateway requires local currency

if ( $current_currency === 'USD' ) {

// Convert variables back before pushing transaction details

}

return $params;

}

`

By configuring WooCommerce's native Geolocation, applying conversions dynamically via pricing hooks, and keeping checkouts synchronized, you build an efficient, plugin-free international store that loads in under 1 second.

Related posts

Cross-Listing Inventory Management Without Overselling
E-commerce14 min read

Cross-Listing Inventory Management Without Overselling

A practical cross-listing inventory architecture covering canonical SKUs, stock states, reservations, marketplace mappings, order events, synchronization, reconciliation and recovery.

Read article →

Depop Pricing Strategy: Fees, Offers and Profit
E-commerce13 min read

Depop Pricing Strategy: Fees, Offers and Profit

A practical Depop pricing system covering market research, location-based fees, buyer costs, offers, discounts, bundles, shipping, boosting, returns and contribution.

Read article →

eBay Item Specifics and Product Identifiers Guide
E-commerce14 min read

eBay Item Specifics and Product Identifiers Guide

A complete eBay structured-data guide covering categories, required and recommended item specifics, product identifiers, catalog matching, variations, condition and bulk repair.

Read article →

Author

Anushka Dahanayake

Anushka Dahanayake is the founder of ANUSHKA DAHANAYAKE (PVT) LTD, building SEO-driven content, digital services, and revenue platforms for businesses in Sri Lanka and worldwide.