Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/251.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 当商品数量增加/减少时,如何从商店页面更新购物车?_Php_Wordpress_Woocommerce_Hook Woocommerce - Fatal编程技术网

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

Php 当商品数量增加/减少时,如何从商店页面更新购物车?,php,wordpress,woocommerce,hook-woocommerce,Php,Wordpress,Woocommerce,Hook Woocommerce,下面是我在购物车页面中使用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(

下面是我在购物车页面中使用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 );
});
如果你想检查(),这里有一个链接。

你可以这样使用

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

你能不能检查一下链接,它在工作,但它只是增加了产品,而不是减少了:(我认为它只适用于加号按钮,减号按钮应该有一个不同的脚本。不是吗?减号和加号两个按钮用于数量的增加和减少。它不会从购物车中删除项目。你没有提供任何值。你的脚本只会增加已经添加到购物车按钮中的值。我已经有了解决方案。)请在此处更新,直到答案在此处: