This thread is resolved. Here is a description of the problem and solution.
Problem: The client wants to change the currency based on the URL parameter without needing a page reload.
Solution: 1. Set up a Currency Switcher as detailed in our documentation: Multi-currency Support for WooCommerce. 2. If using multiple languages, set currency per language as explained in the same guide. 3. For a custom solution, follow these steps: - Retrieve the "currency" parameter from the URL. - Sanitize the parameter to prevent switching to a non-existent currency. - Use the
wcml_client_currency
hook to force the currency switch. For details, see: wcml_client_currency. - It is recommended to force a page reload after the currency change. 4. Consider additional hooks for post-switch actions:
So default for our EN shop is currency EUR but if someone visit the url like this: hidden link
It has to be in GPB. We can change the cookie but then it is available after a reload an not directly. Any hook we can use? We already checked this hook "wcml_set_client_currency" but that's not working.
We know the currency switcher but needs a method to change the currency by url. We have searched for the correct hook but didn't found any that gives the ability to set the correct currnecy directly.
For example:
domain.nl?currency=EUR = SHow all prices in EUR
domain.nl?currency=GPB = SHow all prices in GPB
Default is EUR.
We can use a function for this. We already test with chaning the cookie, that's working only after the visitor refresh the page.
I think this leads to a custom coding solution which is unfortunately out of the scope of this forum.
However, as per my understanding, you can adopt the following workaround via custom coding:
- Grab the value of "currency" parameter from URL.
- Sanitize the parameter properly, because a user can switch to a non existing currency if done improperly.
- Force switching the currency by using "wcml_client_currency" WCML hook (https://wpml.org/wcml-hook/wcml_client_currency/).
- If the currency is changed in the filter, we strongly recommend you force the page to reload. See details on the mentioned guide.
Additionally, you may also be interested in following hooks, in case you want to handle things after currency has been switched: