Get The Correct WooCommerce Product Price in AJAX Call When Using WPML

It was recently brought to my attention that when using my WooCommerce QuickView plugin with WPML, everything was translated correctly except the price. If multi currency was enabled, the price was still displayed in the default store currency.

After looking into this for a while, I found the solution and felt it was worth sharing, although probably a very niche issue.

The solution is to enable multi currency in your AJAX action using a filter provided by WPML.

You can drop this code into your plugin or theme, or for the less experienced, try using theĀ Code Snippets plugin.

The function accepts one parameter, $ajax_actions. This is an array of AJAX actions where multi currency should be applied.

Simply add your AJAX action to the array and return the results. Your prices will now be converted to the correct currency.