Woocommerce: Losing currency in ajax call

I have a Woocommerce site that uses the Woocommerce Multilingual plugin from WPML to handle currencies. I am trying to get the cart amount in an AJAX-call, but I get wrong currency for some reason. If I use the same method (get_cart_subtotal) in a page template the correct currency is used.

Here is my very simple ajax-action:

Read More
add_action('wp_ajax_nopriv_get_cart_total', function(){
    global $woocommerce;
    echo $woocommerce->cart->get_cart_subtotal();
});

I am using:

  • WooCommerce 2.5.5
  • WPML Multilingual CMS 3.3.8 WooCommerce
  • Multilingual 3.7.13

Related posts

1 comment

  1. Try to use wc_ajax instead of wp_ajax. Change also code in .js – it could be something like that:

    $.post(wc_add_to_cart_params.wc_ajax_url.toString().replace('%%endpoint%%', 'get_cart_total'), data, function(response) {
            if (!response) {
                return;
            } else {
                //do something
            }
    });
    

Comments are closed.