Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
The client needed to retrieve the currency list with the exchange rates for their site using WPML and was unsure which hook to use.
Solution:
We advised the client to access the currency list and exchange rates through the

_wcml_settings

option in WordPress, which is a serialized array containing WooCommerce Multilingual (WCML) settings. Specifically, the

currency_options

key within this array holds the necessary data. Here is a step-by-step guide on how to retrieve this information:

function get_wcml_currency_rates() {
    $wcml_settings = get_option( '_wcml_settings' );
 
    if ( ! isset( $wcml_settings['currency_options'] ) ) {
        return [];
    }
 
    $currency_options = $wcml_settings['currency_options'];
    $rates = [];
 
    foreach ( $currency_options as $currency_code => $currency_data ) {
        // WCML may store 'rate' as string or float
        $rate = isset( $currency_data['rate'] ) ? floatval( $currency_data['rate'] ) : 0;
 
        // Only include if rate is > 0
        if ( $rate > 0 ) {
            $rates[ $currency_code ] = $rate;
        }
    }
 
    return $rates;
}
//For testing
$rates = get_wcml_currency_rates();
echo '<pre>';
print_r($rates);
echo '</pre>
<p>';<br />
// Output might be: ['USD' => 1.08, 'GBP' => 0.86, 'AUD' => 1.64]<br />

Please note that we do not typically provide custom code solutions. For further customization, you might need to hire an independent contractor.

If this solution does not resolve your issue or seems outdated, we recommend checking related known issues at https://wpml.org/known-issues/, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If the problem persists, please open a new support ticket.

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 4 replies, has 1 voice.

Last updated by marioG-45 2 weeks, 2 days ago.

Assisted by: Andreas W..

Author Posts
May 30, 2025 at 6:45 am #17090508

marioG-45

Background of the issue:
I am trying to get the currency list with the currency exchange rate for my site hidden link using WPML.

Symptoms:
I am unsure which hook to use to get the currency list with the currency exchange rate.

Questions:
Which hook do I need to use to get the currency list with the currency exchange rate?

May 30, 2025 at 7:22 am #17090619

marioG-45

Hello WPML team,

I hope you guys can get the problem. As I'm not able to get the currency information like exchange rate etc...

I'm looking for the solution. Waiting for the good news.
Thanks

May 30, 2025 at 10:11 pm #17093502

Andreas W.
WPML Supporter since 12/2018

Languages: English (English ) Spanish (Español ) German (Deutsch )

Timezone: America/Lima (GMT-05:00)

Hello,

What you're looking for is stored in the WordPress option called _wcml_settings. This is a serialized array that contains various WooCommerce Multilingual (WCML) settings, including a key named currency_options. The currency_options array holds all the configured currencies along with their exchange rates and related formatting settings.

This worked on my test:

function get_wcml_currency_rates() {
    $wcml_settings = get_option( '_wcml_settings' );

    if ( ! isset( $wcml_settings['currency_options'] ) ) {
        return [];
    }

    $currency_options = $wcml_settings['currency_options'];
    $rates = [];

    foreach ( $currency_options as $currency_code => $currency_data ) {
        // WCML may store 'rate' as string or float
        $rate = isset( $currency_data['rate'] ) ? floatval( $currency_data['rate'] ) : 0;

        // Only include if rate is > 0
        if ( $rate > 0 ) {
            $rates[ $currency_code ] = $rate;
        }
    }

    return $rates;
}

For testing:

$rates = get_wcml_currency_rates();
echo '<pre>';
print_r($rates);
echo '</pre>';
// Output might be: ['USD' => 1.08, 'GBP' => 0.86, 'AUD' => 1.64]

Take kindly note, that our support is not obligated nor expected to provide custom code solutions. For this purpose, you usually should contact an independent contractor.

Best regards
Andreas

June 2, 2025 at 4:44 am #17096216

marioG-45

Hello Andreas W,

Okay I'll test that code and let you know.
Thanks

June 2, 2025 at 6:04 am #17096318

marioG-45

Hello Andreas W,
It's working.
Thanks