简体   繁体   中英

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/

  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/

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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