How To Update Cart On Quantity Change Value

Here we learn about how to update cart on quantity change value.

1. Custom code copied and paste into your child theme’s file and folder.

2. we have to hide the ‘Update cart’ button.

Add below CSS code on file ‘child-theme/style.css’.

.woocommerce button[name="update_cart"],
.woocommerce input[name="update_cart"] {
     display: none;
}

3. Enqueue js file ‘child-theme/functions.php’.

<?php
function myblog_enqueue_styles() {
  wp_enqueue_script( 'ajax-script', get_stylesheet_directory_uri().'/js/custom.js' , array( 'jquery' ) );
}
add_action( 'wp_enqueue_scripts', 'myblog_enqueue_styles' );
?>

4. Add below JS code on file ‘child-theme/js/custom.js’.

<script>
jQuery(function(){
  jQuery( '.woocommerce' ).on( 'change', 'input.qty', function(){
    jQuery( '[ name="update_cart" ]' ).trigger( 'click' );
  });
});
</script>

OUTPUT:

 

1 Comment

  1. Amir

    hello sir,
    the code does not work well for me, I have to click twice at quantity increment button. If I click one time, its does do anything.

    0
    0
    Reply

Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe

Select Categories