I
I
Ivan2020-06-27 12:27:30
WordPress
Ivan, 2020-06-27 12:27:30

WooCommerce how to auto refresh without a button?

In WooCommerce, you can change the number of products in the cart, I need to do the same, but in the modal window when adding.

I collected something from what I took in the basket, it turned out the following.

<form class="woocommerce-cart-form" action="<?php echo esc_url(wc_get_cart_url()); ?>" method="post">
        <div class="shop_table_responsive cart woocommerce-cart-form__contents">
              <?php
              foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
              	if($cart_item['data']->get_id() == $product->id)
              	{
                    $_product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key); ?>
          <div class="row cart_product_row woocommerce-cart-form__cart-item <?php echo esc_attr(apply_filters('woocommerce_cart_item_class', 'cart_item', $cart_item, $cart_item_key)); ?>">
                      <div class="product-quantity" data-title="<?php esc_attr_e('Quantity', 'woocommerce'); ?>">
                          <?php
                          if ($_product->is_sold_individually()) {
                              $product_quantity = sprintf('1 <input type="hidden" name="cart[%s][qty]" value="1" />', $cart_item_key);
                          } else {
                              echo '<div class = "on_small" style="font-size: 14px; color: #b0b0b0;  margin-bottom: 10px; font-weight: 400;">Количество</div >';
                              $product_quantity = woocommerce_quantity_input(
                                      array(
                                          'input_name' => "cart[{$cart_item_key}][qty]",
                                          'input_value' => $cart_item['quantity'],
                                          'max_value' => $_product->get_max_purchase_quantity(),
                                          'min_value' => '0',
                                          'product_name' => $_product->get_name(),
                                      ),
                                      $_product,
                                      false
                              );
                          }
                          echo apply_filters('woocommerce_cart_item_quantity', $product_quantity, $cart_item_key, $cart_item); // PHPCS: XSS ok.
                    }
                }
                ?>	
                		</div>
                    </div>
                <div class="row cart_product_row coupon_row">
                    <div class="col-12">
                        <button type="submit" class="button green_btn mt-5" name="update_cart" value="<?php esc_attr_e('Update cart', 'woocommerce'); ?>"><?php esc_html_e('Update cart', 'woocommerce'); ?></button>
                        <?php wp_nonce_field('woocommerce-cart', 'woocommerce-cart-nonce'); ?>
                    </div>
                </div>
                </div>
              </form>


That's just the next problem.
In the basket, when we wrote some figure (how many products we choose), he himself sends a request and updates. And my request itself is not sent, only if you manually click on the "update" button.

In the basket, the button is hidden, but it is somehow pressed by itself. If you remove it, nothing will happen.
5ef710ad74a2a255381792.png

This button does not automatically disappear for me, I need to click on it.
5ef710fe1bc35561200750.png

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question