Ecommerce Shopify WordPress Discussion

WooCommerce variation increment quantity acts directly on the cart

I am using WooCommerce and for the variable product, with variations, I have a choose option, when user chooses an option, they can click on add to cart, and it adds it to the cart, as supposed. But I have also a quantity which you can increment or decrement and if I click on plus or minus it adds or removes the quantity direct to or from the cart, I want only the product only gets added to the cart after clicking on add to cart (submit). This is what I have in the functions.php in the child theme. add_action('wp_ajax_add_to_cart', 'ajax_add_to_cart'); add_action('wp_ajax_nopriv_add_to_cart', 'ajax_add_to_cart'); function ajax_add_to_cart() { check_ajax_referer('ajax_add_to_cart_nonce', 'nonce'); if (isset($_POST['product_id'])) { $product_id = intval($_POST['product_id']); WC()->cart->add_to_cart($product_id); die(); } } add_filter('woocommerce_add_to_cart_fragments', 'cart_fragments'); function cart_fragments($fragments) { ob_start(); ?> <span class="cart-contents"><?php echo WC()->cart->get_cart_contents_count(); ?></span> <?php $fragments['span.cart-contents'] = ob_get_clean(); return $fragments; } And this is the variations add to cart: defined( 'ABSPATH' ) || exit; global $product; ?> <div class="woocommerce-variation-add-to-cart variations_button"> <?php do_action( 'woocommerce_before_add_to_cart_button' ); ?> <div class="quantity"> <label class="screen-reader-text" for="quantity_<?php echo esc_attr( $product->get_id() ); ?>">my-quantity</label> <div class="quantity_deel"> <div class="plus-min-btns"> <button onclick="decrementQuantity()">-</button> <input type="number" id="quantity_<?php echo esc_attr( $product->get_id() ); ?>" class="input-text qty text" name="quantity" value="1" aria-label="Product quantity" size="4" min="1" step="1" inputmode="numeric" autocomplete="off"> <button onclick="incrementQuantity()">+</button> </div> <div> <button type="submit" class="single_add_to_cart_button button alt<?php echo esc_attr( wc_wp_theme_get_element_class_name( 'button' ) ? ' ' . wc_wp_theme_get_element_class_name( 'button' ) : '' ); ?>"><?php echo esc_html( $product->single_add_to_cart_text() ); ?></button> </div> </div> </div> <?php do_action( 'woocommerce_after_add_to_cart_button' ); ?> <input type="hidden" name="add-to-cart" value="<?php echo absint( $product->get_id() ); ?>" /> <input type="hidden" name="product_id" value="<?php echo absint( $product->get_id() ); ?>" /> <input type="hidden" name="variation_id" class="variation_id" value="0" /> </div> <script> function decrementQuantity() { var quantityInput = document.getElementById("quantity_<?php echo esc_attr( $product->get_id() ); ?>"); var currentValue = parseInt(quantityInput.value); if (currentValue > 1) { quantityInput.value = currentValue - 1; } } function incrementQuantity() { var quantityInput = document.getElementById("quantity_<?php echo esc_attr( $product->get_id() ); ?>"); var currentValue = parseInt(quantityInput.value); quantityInput.value = currentValue + 1; } </script> Can someone explain why is this not working?
TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.