作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 updated_cart_totals
jQuery 事件来监听 WooCommerce 购物车更新。每当我更新购物车时它都会起作用,但我还需要获取新的购物车总数。
这是我监听“updated_cart_totals”事件的基本代码:
$(document.body).on('updated_cart_totals', function (event) {
alert("in here");
});
最佳答案
要使用 updated_cart_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
});
});
它应该按预期工作。
关于javascript - 在 'updated_cart_totals' jQuery 事件上获取 WooCommerce 刷新购物车总数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57663997/
我正在使用 updated_cart_totals jQuery 事件来监听 WooCommerce 购物车更新。每当我更新购物车时它都会起作用,但我还需要获取新的购物车总数。 这是我监听“updat
我是一名优秀的程序员,十分优秀!