ajax在woocommerce中增加或减少数量?

当我进入CART页面时,我正在使用此代码更新购物车-

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',1000 );
});

但是它不起作用,如何解决呢?

lumnstar 回答:ajax在woocommerce中增加或减少数量?

Remove disabled property before update cart

jQuery("[name='update_cart']").prop("disabled",false);

So code will be:

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']").prop("disabled",false);
       jQuery('[name="update_cart"]').trigger('click');
    },1000 );
});
,
var timeout;

jQuery( function( $ ) {
$('.woocommerce').on('change',function(){

    if ( timeout !== undefined ) {
        clearTimeout( timeout );
    }

    timeout = setTimeout(function() {
        $("[name='update_cart']").trigger("click");
    },1000 ); // 1 second delay,half a second (500) seems comfortable too

   });
} );
本文链接:https://www.f2er.com/3162669.html

大家都在问