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: Exception
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: Symptoms: Questions: |
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; } |