简体   繁体   English

当 woocommerce 中的产品数量增加/减少时,如何从商店页面更新购物车?

[英]How to update cart from shop page when product quantity increase/decrease in woocommerce?

Here is the code I am using for updating my cart with ajax in CART page-这是我用于在购物车页面中使用 ajax 更新购物车的代码-

jQuery('div.woocommerce').on('change keyup mouseup', 'input.qty', function(){ // keyup and mouseup for Firefox support
    if (timeout != undefined) clearTimeout(timeout); //cancel previously scheduled event
    if (jQuery(this).val() == '') return; //qty empty, instead of removing item from cart, do nothing
    timeout = setTimeout(function() {
        jQuery('[name="update_cart"]').trigger('click');
    }, 1000 );
});

Its working fine, but my problem is when I try with same code in shop page its not updating my cart - Here is what i have tried -它工作正常,但我的问题是当我在商店页面中尝试使用相同的代码时,它没有更新我的购物车 - 这是我尝试过的 -

jQuery('li.product').on('change keyup mouseup', 'input.qty', function(){ // keyup and mouseup for Firefox support
    if (timeout != undefined) clearTimeout(timeout); //cancel previously scheduled event
    if (jQuery(this).val() == '') return; //qty empty, instead of removing item from cart, do nothing
    timeout = setTimeout(function() {
        jQuery('[name="update_cart"]').trigger('click');
    }, 1000 );
});

Here is the link if u want to check( https://cdn.royalancer.co.uk/test/ ).如果你想检查,这里是链接( https://cdn.royalancer.co.uk/test/ )。

You can use like this你可以这样使用

jQuery('li.product').on('change keyup mouseup', 'button.plus.qib-button,button.minus.qib-button', function(){ // keyup and mouseup for Firefox support
   var timeout;
   var this_ = jQuery(this);
       timeout = setTimeout(function() {
       this_.parent().parent().find('.ajax_add_to_cart').trigger( 'click' );
       clearTimeout(timeout);
    }, 1000 );
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM