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

时间:2019-11-04 17:08:37

标签: php wordpress woocommerce hook-woocommerce

这是我用来在CART页面中用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 );
});

它工作正常,但是我的问题是,当我在商店页面中尝试相同的代码时,它没有更新我的购物车- 这是我尝试过的-

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 );
});

如果您要检查(https://cdn.royalancer.co.uk/test/),这是链接。

1 个答案:

答案 0 :(得分:0)

您可以这样使用

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 );
});