更新了送货选项后,需要在结帐页面上通过ajax调用来初始化jQuery函数,并且已触发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的自定义事件触发器,并且效果很好。不确定结帐页面为何不是这种情况。

最佳答案

正确的自定义事件:updated_checkout

有问题的代码段正在侦听不正确的Woocommerce自定义事件。

在这种情况下,要侦听的正确的自定义事件是updated_checkout

选择新的送货方式时,Woocommerce会触发ajax调用以更新购物车总额以反映所选送货方式的价格,然后触发updated_checkout

因此,如果侦听updated_checkout而不是updated_shipping_method,则会按预期触发脚本。

07-24 09:47
查看更多