Woocommerce

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:

 

Rahul Prajapat

I’m Rahul Prajapat. I’m a WordPress developer and Author at TheCodeHubs. I have good skill of Html, CSS, JQuery, SQL, Web API, PSD to HTML/PSD to WordPress, WordPress Theme/Plugin Customization, create or modify short code, customize visual composer short code or integrate new short code with visual composer, can create custom metabox for any post type in WordPress admin.

View Comments

  • 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.

Recent Posts

Testing hk

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Operation

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

TETS NEW

test

2 years ago