jQuery函数需要在发布选项更新后,在结帐页面上,通过ajax调用初始化,并且已触发Woocommerce自定义事件 updated_shipping_method
.
我的jQuery代码片段设置为侦听此事件 - 但这不符合预期 .
jQuery( document.body ).on( 'updated_shipping_method', function(){
// Code stuffs
// has the function initialized after the event trigger?
console.log('on updated_shipping_method: function fired');
});
我已经尝试了 updated_wc_div
自定义事件也无济于事 .
我在购物车页面上使用类似的方法,几乎是逐字逐句地收听 updated_cart_totals
的自定义事件触发器,它完美无缺 . 不确定为什么结帐页面不是这种情况 .
1 回答
Correct Custom Event:
updated_checkout
有问题的代码片段正在侦听错误的Woocommerce自定义事件 .
在这种情况下要收听的正确自定义事件是
updated_checkout
.选择新的送货方式时,Woocommerce会触发ajax调用以更新购物车总数以反映所选送货方式的价格,然后触发
updated_checkout
.因此,如果收听
updated_checkout
,而不是updated_shipping_method
,脚本将按预期触发 .