Skip to content Skip to sidebar

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 1 replies, has 0 voices.

Last updated by frederikc-7 1 month, 2 weeks ago.

Assisted by: Shekhar Bhandari.

Author Posts
November 25, 2025 at 9:53 am

frederikc-7

Background of the issue:
I am trying to implement dynamic currency conversion for a static shipping charge value of '49' USD on my WooCommerce store, earmuffz.com. The goal is to convert this static value to the user's local currency based on their geolocation. I have multi-currency and geolocation detection enabled in WPML/WCML.

Symptoms:
The static shipping charge value is displayed as '49' USD for all users, regardless of their location. It does not change based on user geolocation.

Questions:
What is the best approach to convert static currency values to dynamic currency display based on user geolocation?
Can you provide implementation guidance for this currency conversion feature?

November 25, 2025 at 11:32 am #17607764

Shekhar Bhandari
WPML Supporter since 03/2015

Languages: English (English )

Timezone: Asia/Kathmandu (GMT+05:45)

Hello there,

As mentioned earlier, I modified the code as mentioned earlier and added the following on the theme functions.php file

function earmuffz_get_current_currency() {
    // Try WCML filter
    $currency = apply_filters( 'wcml_currency', null );

    // Try SESSION (WCML stores currency here when multi-currency is enabled)
    if ( empty( $currency ) && isset( $_SESSION['wcml_currency'] ) && $_SESSION['wcml_currency'] !== '' ) {
        $currency = $_SESSION['wcml_currency'];
    }

    // Fallback to WooCommerce default
    if ( empty( $currency ) ) {
        $currency = get_woocommerce_currency();
    }

    return $currency;
}

function my_cart_shipping_total_shortcode() {
    $base_price = 45;

    // Convert using WCML if available
    $converted_price = apply_filters( 'wcml_raw_price_amount', $base_price );

    // If for some reason it fails, at least format base price
    if ( ! $converted_price ) {
        $converted_price = $base_price;
    }

    return wc_price( $converted_price, [ 'currency' => earmuffz_get_current_currency() ] );
}
add_shortcode( 'earmuffz_shipping', 'my_cart_shipping_total_shortcode' );

You can know more about WCML hooks here: https://wpml.org/documentation/related-projects/woocommerce-multilingual/wcml-hooks-reference/

This works inside the elementor editor, but not on the front-end, so I would suggest you create a new page with just the shortcode and see if it works, if yes, it must be due to elementor not refreshing the page content.

In that content, you can check how you can update content in elementor widget when you change currency.

Look forward to your reply.

Thanks

December 4, 2025 at 7:03 am #17632641

frederikc-7

resolved