加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

在WooCommerce AJAX送货方法更新后运行jQuery

发布时间:2020-12-16 02:50:06 所属栏目:百科 来源:网络整理
导读:jQuery函数需要在发布选项更新后,在结帐页面上,通过ajax调用初始化,并且已触发Woocommerce自定义事件updated_shipping_method. 我的jQuery代码片段设置为侦听此事件 – 但这不符合预期. jQuery( document.body ).on( 'updated_shipping_method',function(){
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的自定义事件触发器,它完美地工作.不确定为什么结帐页面不是这种情况.

解决方法

更正自定义事件:updated_checkout

有问题的代码片段正在侦听错误的Woocommerce自定义事件.

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

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读