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 2 weeks, 2 days ago.
Assisted by: Andreas W..