Javascript 在';更新的购物车总数';jQuery事件

Javascript 在';更新的购物车总数';jQuery事件,javascript,jquery,wordpress,woocommerce,cart,Javascript,Jquery,Wordpress,Woocommerce,Cart,我正在使用updated\u cart\u totalsjQuery事件来侦听购物车更新。每当我更新我的购物车时,它都会工作,但我也需要获得新的购物车总数 以下是我收听“更新的购物车总计”事件的基本代码: $(document.body).on('updated_cart_totals', function (event) { alert("in here"); }); 要使用updated\u cart\u totals事件获取刷新的购物车总计,请尝试以下操作: jQuery( fu

我正在使用
updated\u cart\u totals
jQuery事件来侦听购物车更新。每当我更新我的购物车时,它都会工作,但我也需要获得新的购物车总数

以下是我收听“更新的购物车总计”事件的基本代码:

$(document.body).on('updated_cart_totals', function (event) {
    alert("in here");
});

要使用
updated\u cart\u totals
事件获取刷新的购物车总计,请尝试以下操作:

jQuery( function($){
    $(document.body).on('updated_cart_totals', function () {
        // Get the formatted cart total
        var total = $('div.cart_totals tr.order-total span.woocommerce-Price-amount').html();

        total = total.replace(/,/g, '.'); // Replace comas by points
        total = parseFloat(total).toFixed(2); // Extract float number and format it with 2 decimals

        console.log(total); // Display it in the browser console
        alert(total); // Display it in an alert box
    });
});
它应该像预期的那样工作