简体   繁体   English

小型jQuery更新购物车停止工作(Woocommerce / Wordpress)

[英]Small jQuery to update cart stopped working (Woocommerce/Wordpress)

I created a small script so the cart would update itself after I changed the value and clicked outside the input-field. 我创建了一个小脚本,以便在更改值并在输入字段之外单击后,购物车会自动更新。 But now it stopped working and I have no idea why :/ 但是现在它停止工作了,我不知道为什么:/

  1. You need to put something in the cart (press: "In den Warenkorb"): http://vamedics.com/de/shop/2-lendenwirbel/ 您需要在购物车中放入一些物品(按:“ In den Warenkorb”): http ://vamedics.com/de/shop/2-lendenwirbel/

  2. Now at the cart just change the number in the input field and it should refresh the site but it doesn't change the price nor the quantity: http://vamedics.com/de/warenkorb/ 现在,在购物车上只需更改输入字段中的数字即可刷新网站,但不会更改价格或数量: http : //vamedics.com/de/warenkorb/

It may not be the best jquery in the world but it did its job :/ It would just press the refresh cart button (it's hidden via display: none) and refresh everything while updating the cart 它可能不是世界上最好的jquery,但它确实完成了它的工作:/只需按刷新购物车按钮(通过显示隐藏:无)并在更新购物车时刷新所有内容

Here is the code: 这是代码:

 $(document).ready(function() { $('#input-qty').each(function() { var elem = $(this); elem.data('oldVal', elem.val()); elem.bind("propertychange change click keyup input paste", function(event){ if (elem.data('oldVal') != elem.val()) { elem.data('oldVal', elem.val()); $("#input-qty").focusout(function() { $('input[type="submit"]:nth-child(2)').trigger('click'); }); } }); }); }); 

Can someone help me? 有人能帮我吗?

You have a hidden mobile version of the cart which contains the quantity aswell. 您的购物车有一个隐藏的移动版本,其中也包含数量。 When you update the page by sending the form you're sending duplicate names for everything. 通过发送表单更新页面时,您将为所有内容发送重复名称。 The cart and the quantity. 购物车和数量。

This was my request when I changed the quantity: 这是我更改数量时的要求:

cart%5B9dd3ecb6819c19341cce4399afa2c7dd%5D%5Bqty%5D=1&cart%5B9dd3ecb6819c19341cce4399afa2c7dd%5D%5Bqty%5D=10&coupon_code=&update_cart=Warenkorb+aktualisieren&_wpnonce=b5b38505ed&_wp_http_referer=%2Fde%2Fwarenkorb%2F

You can see that the cart and its quantity is specified twice. 您可以看到购物车及其数量被指定了两次。 Once with the old value and once with the new value. 一次使用旧值,一次使用新值。

Either make a separate form when you're submitting through JS or make sure you're changing both quantities. 通过JS提交时,请单独填写表格,或者确保同时更改两个数量。

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

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