Man*_*ndo 11 wordpress woocommerce
WooCommerce:
我有一些jQuery加载在document.ready上影响数量输入框.效果很好.
我的问题是,当我更新购物车/删除项时,jQuery需要再次运行,因为AJAX调用将其杀死(刷新它).是否有一些我可以添加的钩子/过滤器会在购物车更新后重新运行我的脚本?我搜索过,找不到任何东西(或者我可能不知道我在寻找什么).
谢谢!!!!
hel*_*ing 32
WooCommerce脚本内置了几个自定义事件.您自己的脚本可以监听这些事件并在触发时运行您自己的代码.对你的情况最明显的可能是updated_cart_totals但updated_wc_div也可能有帮助,我不确定没有测试.经过测试和工作.
$( document.body ).on( 'updated_cart_totals', function(){
//re-do your jquery
});
Run Code Online (Sandbox Code Playgroud)
我还需要在用户从购物车中删除项目后运行一个函数,并且上述事件updated_cart_totals或updated_wc_div对我不起作用。
在深入研究Woocommerce前端代码之后
[/wp-content/plugins/woocommerce/assets/js/frontend/add-to-cart.min.js]
我发现了这些事件:
$(document.body).on('added_to_cart removed_from_cart', do_magic);
Run Code Online (Sandbox Code Playgroud)
这些工作就像一个魅力!
小智 8
就我而言,我必须添加以下内容:
jQuery(document.body).on('removed_from_cart updated_cart_totals', function () {
location.reload();
});
Run Code Online (Sandbox Code Playgroud)
因为我有一个巨大的定制与js cart提交