admin管理员组文章数量:1406926
I am using updated_cart_totals
jQuery event to listen to WooCommerce cart updates. It works whenever I update my cart, but I need to get the new cart total as well.
Here is my basic code to listen 'updated_cart_totals' event:
$(document.body).on('updated_cart_totals', function (event) {
alert("in here");
});
I am using updated_cart_totals
jQuery event to listen to WooCommerce cart updates. It works whenever I update my cart, but I need to get the new cart total as well.
Here is my basic code to listen 'updated_cart_totals' event:
$(document.body).on('updated_cart_totals', function (event) {
alert("in here");
});
Share
Improve this question
edited Aug 28, 2019 at 2:52
LoicTheAztec
255k24 gold badges399 silver badges446 bronze badges
asked Aug 26, 2019 at 19:40
MahiMahi
532 silver badges6 bronze badges
1 Answer
Reset to default 5To get the refreshed cart total using updated_cart_totals
event try the following:
jQuery( function($){
$(document.body).on('updated_cart_totals', function () {
// Get the formatted cart total
var total = $('div.cart_totals tr.order-total span.woomerce-Price-amount').html();
total = total.replace(/,/g, '.'); // Replace as 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
});
});
It should work as expected.
本文标签: javascriptGet WooCommerce refreshed cart total on 39updatedcarttotals39 jQuery eventStack Overflow
版权声明:本文标题:javascript - Get WooCommerce refreshed cart total on 'updated_cart_totals' jQuery event - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744980065a2635760.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论