WooCommerce: Save Order Currency Exchange Rate

If you run a WooCommerce store with multiple currencies, you know that exchange rates can fluctuate constantly. By default, WooCommerce only stores the order total in the currency used at checkout, which means you might lose track of the actual conversion rate applied at that moment. This can make accounting, reporting, or analyzing profitability across currencies tricky.

A simple solution is to save the exchange rate used for each order directly in the order meta. This way, you can always see the exact rate applied when the customer paid, calculate your earnings in your main store currency, and avoid discrepancies caused by later rate changes.

In this snippet, we’ll show you how to capture the exchange rate at checkout and save it with the order. This is particularly helpful for stores that report in a single currency, do accounting in multiple currencies, or want precise historical financial records.

PHP Snippet: Save WooCommerce Order Exchange Rate

This snippet automatically saves the exchange rate applied for each WooCommerce order, regardless of the currency used at checkout. It reads the main store currency from WooCommerce settings and calculates the conversion rate relative to that.

The exchange rate is then stored in a generic order meta field named _order_currency_rate, making it easy to reference later for accounting, reporting, or profitability analysis.

By saving the rate at the moment of purchase, you ensure your financial records remain accurate even if exchange rates fluctuate in the future. This snippet works with any currency setup in WooCommerce.

/**
 * @snippet       Get WooCommerce order currency exchange rate
 * @tutorial      https://businessbloomer.com/woocommerce-customization
 * @author        Rodolfo Melogli, Business Bloomer
 * @compatible    WooCommerce 10
 * @community     Join https://businessbloomer.com/club/
 */

add_action( 'woocommerce_checkout_create_order', 'bbloomer_maybe_save_exchange_rate', 10, 2 );

function bbloomer_maybe_save_exchange_rate( $order, $data ) {

    // Get main store currency
    $main_currency = get_option( 'woocommerce_currency' );

    // Get order currency
    $order_currency = $order->get_currency();

    // Save exchange rate with the order
    if ( $order_currency !== $main_currency ) {
        $xml = @simplexml_load_file( 'https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml' );
        if ( ! $xml ) return;
        foreach ( $xml->Cube->Cube->Cube as $cube ) {
            if ( (string) $cube['currency'] === $order_currency ) {
                $rate = (string) $cube['rate'];
                $order->update_meta_data( '_order_currency_rate', $rate );
                $order->save();
                break;
            }
        }
    }

}

Demo

On my test website, the main currency is EUR. I also have a custom currency switcher on my classic checkout page.

So, I place a new order in USD and with the snippet above, I can now see the value of the “_order_currency_rate” meta inside the order admin page “Custom Fields” section:

Value is 1.1575, and in fact as of now (November 12, 2025 at 10am Italy time), it’s the correct exchange rate: 1 EUR = 1.1575 USD.

Now I can use this in my PDF invoice or for accounting purposes, because I may need the equivalent EUR value!

Where to add custom code?

You should place custom PHP in functions.php and custom CSS in style.css of your child theme: where to place WooCommerce customization?

This code still works, unless you report otherwise. To exclude conflicts, temporarily switch to the Storefront theme, disable all plugins except WooCommerce, and test the snippet again: WooCommerce troubleshooting 101

Related content

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli

Questions? Feedback? Customization? Leave your comment now!
_____

If you are writing code, please wrap it like so: [php]code_here[/php]. Failure to complying with this, as well as going off topic or not using the English language will result in comment disapproval. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining the Business Bloomer Club to get quick WooCommerce support. Thank you!

Your email address will not be published. Required fields are marked *