每当客户修改项目数量时,我都会尝试更新自动购物车。当我没有登录时它已经工作了,但奇怪的是当我登录时,这个特定的脚本将无法正常工作。
jQuery的:
var timeout;
jQuery('div.woocommerce').on('change', 'input.qty', function(){
if(typeof timeout !== undefined) clearTimeout(timeout);
timeout = setTimeout(function() {
jQuery("[name='update_cart']").prop("disabled", false);
jQuery("[name='update_cart']").trigger("click");
}, 1500);
});
儿童主题的功能:
add_action( 'wp_enqueue_scripts', 'dp_cart_refresh_update_qty' );
function dp_cart_refresh_update_qty() {
if (is_cart()) {
wp_enqueue_script(
'cart_auto_refresh',
get_stylesheet_directory_uri() . '/js/cart_auto_refresh.js',
array('jquery')
);
}
}
发生这种情况时没有错误控制台输出它只是没有做任何事情,甚至没有触发。我已经尝试将console.log放在代码的某些部分上,没有。
我已经使用这个确切的方法添加了其他几个jQuery,并且所有这些方法都正常工作,对于管理员和已注销的用户。
任何帮助表示赞赏。谢谢。
编辑:
我检查了“update_cart”按钮,它在购物车页面上,虽然我把它设置为显示:无
<input class="btn btn-alternative" name="update_cart" value="Update Shopping Cart" type="submit">
尝试像这样包装jQuery代码:
jQuery(function($) {
var timeout;
jQuery('div.woocommerce').on('change', 'input.qty', function() {
if (typeof timeout !== undefined)
clearTimeout(timeout);
timeout = setTimeout(function() {
jQuery("[name='update_cart']").prop("disabled", false);
jQuery("[name='update_cart']").trigger("click");
}, 1500);
});
});