I
I
Ivseti2021-09-29 09:35:53
JavaScript
Ivseti, 2021-09-29 09:35:53

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

2 answer(s)
A
Artem Zolin, 2021-09-29
@Ivseti

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:

  • wc-quantity-increment
  • wc-quantity-increment-buttons

A
Alexey Dubrovin, 2021-09-29
@alekcena

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 question

Ask a Question

731 491 924 answers to any question