在 WooCommerce AJAX 购物车更新后运行 jQuery [英] Run jQuery after WooCommerce AJAX cart update

查看:20
本文介绍了在 WooCommerce AJAX 购物车更新后运行 jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

WooCommerce:

WooCommerce:

我有一些 jQuery 加载到 document.ready 上,影响数量输入框.效果很好.

I have some jQuery that loads on document.ready that effects the quantity input box. Works great.

我的问题是,当我更新购物车/删除项目时,jQuery 需要再次运行,因为 AJAX 调用会杀死它(刷新它).我可以添加一些钩子/过滤器,以便在购物车更新后再次运行我的脚本吗?我搜索过但找不到任何东西(或者我可能不知道我在找什么).

My issue is that when I update the cart/delete item, the jQuery needs to run again because the AJAX call kills it (refreshes it). Is there some hook/filter I can add that will re-run my script again after a cart update? Ive searched and can't find anything (or maybe I'm not aware of what I am looking for).

谢谢!!!!

推荐答案

WooCommerce 脚本有几个 自定义事件 内置.您自己的脚本可以侦听这些事件并在它们被触发时运行您自己的代码.最明显的可能是 updated_cart_totalsupdated_wc_div 也可能有帮助,我不确定没有测试.经测试有效.

The WooCommerce scripts have several custom events built in. Your own script can listen to these events and run your own code when they are triggered. The most obvious one for your case might be updated_cart_totals but updated_wc_div might also be helpful, I'm not sure without testing. Tested and works.

$( document.body ).on( 'updated_cart_totals', function(){
    //re-do your jquery
});

这篇关于在 WooCommerce AJAX 购物车更新后运行 jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆