Answer the question
In order to leave comments, you need to log in
Why only after the second click does adding and decreasing the quantity in the cart work?
WP Woocommerce
Can't figure out what's wrong with adding and decreasing cart count. The first time I click on "+" or "-" the page reloads and nothing happens, the second time I click everything works.
https://mishka-furs.webtm.ru/cart/
Code:
// Функция кнопки плюс
$('.woocommerce-cart-form__cart-item .quantity .plus').click(function() {
var currentVal = parseInt($(this).parent().find('input').val());
parseInt($(this).parent().find('input').val(currentVal + 1));
$('.actions button').removeAttr('disabled');
$("[name='update_cart']").trigger("click");
setTimeout(function() {
window.location.reload();
}, 250);
});
// Функция кнопки минус
$('.woocommerce-cart-form__cart-item .quantity .minus').click(function() {
var currentVal = parseInt($(this).parent().find('input').val());
parseInt($(this).parent().find('input').val(currentVal - 1));
$('.actions button').removeAttr('disabled');
$("[name='update_cart']").trigger("click");
setTimeout(function() {
window.location.reload();
}, 250);
});
Answer the question
In order to leave comments, you need to log in
It is not necessary to reinvent your wheel every time, you can use ready-made solutions, look for woocommerce quantity increment github
Here are good solutions:
Click on + and then just reload the page via F5
. You first get the page, then the data in the database is updated.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question