1

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:

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
Nocklas
  • 1,367
  • 4
  • 15
  • 27

1 Answers1

0

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
        }
});
Tomasz Winter
  • 287
  • 1
  • 9