Skip Navigation

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.

Tagged: 

This topic contains 1 reply, has 2 voices.

Last updated by Bruno Kos 4 months, 3 weeks ago.

Assisted by: Bruno Kos.

Author Posts
July 4, 2024 at 1:28 pm #15892280

sagiS

Background of the issue:
Inside Admin Panel, WooCommerce Analytics > Coupons > I am trying to check the data for any coupon with currency USD then it is showing me result which is fine but when I select any other currency like Euro, Singapore dollar then it is showing error [ hidden link ]. I have even checked inside network, it is showing status 500 - [ hidden link ], showing first error request [ hidden link ]. But in case of selecting currency as US dollar then it is working fine and showing the result - see screenshot of Network Tab [ hidden link ], [ hidden link ].

Symptoms:
When selecting any currency other than USD in WooCommerce Analytics > Coupons, it shows a status 500 error.

Questions:
Why does selecting currencies other than USD in WooCommerce Analytics > Coupons result in a status 500 error?
How can I resolve the issue of WooCommerce Analytics not working with multiple currencies?

July 4, 2024 at 2:10 pm #15892696

Bruno Kos
Supporter

Languages: English (English ) German (Deutsch ) French (Français )

Timezone: Europe/Zagreb (GMT+01:00)

Can you try this?

add_filter('wcml_client_currency', array($this, 'modify_client_currency'), 10, 1);

public function modify_client_currency($current_currency) {
    // Ensure the WooCommerce session is initialized
    if (class_exists('WooCommerce') && method_exists(WC(), 'initialize_session')) {
        WC()->initialize_session();
    }
    
    // Check if the session is set and return the session currency if available
    if (isset(WC()->session) && WC()->session->get('wcml_curr')) {
        return WC()->session->get('wcml_curr');
    }

    // Check for a currency parameter in the URL and update the session accordingly
    if (isset($_GET['currency']) && $_GET['currency']) {
        if (!is_admin() && class_exists('WCML_Currency_Switcher')) {
            $currencies = Settings::getOrderedCurrencyCodes();
            $currency = strtoupper(esc_attr($_GET['currency']));

            if (in_array($currency, $currencies)) {
                if (isset(WC()->session)) {
                    WC()->session->set('wcml_curr', $currency);
                } else {
                    // Log an error or handle the case where the session is not available
                    error_log('WC()->session is not available');
                }
                return $currency;
            }
        }
    }

    return $current_currency;
}