Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

192
Views
woocommerce plus and minus button doesn't work on ajax update

i copy paste this (global/quantity-input.php) file into my theme directory. And made this changes

`

if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly
}
?>
<div class="quantity">
  <input class="minus" type="button" value="-">
  <input type="number" step="<?php echo esc_attr( $step ); ?>" min="<?php echo esc_attr( $min_value ); ?>" max="<?php echo esc_attr( $max_value ); ?>" name="<?php echo esc_attr( $input_name ); ?>" value="<?php echo esc_attr( $input_value ); ?>" title="<?php echo esc_attr_x( 'Qty', 'Product quantity input tooltip', 'woocommerce' ) ?>" class="input-text qty text" size="4" />
  <input class="plus" type="button" value="+">
</div>

also this jquery code into my js file.

<script type="text/javascript">
    jQuery(document).ready(function($){
        $('.quantity').on('click', '.plus', function(e) {
            $input = $(this).prev('input.qty');
            var val = parseInt($input.val());
            $input.val( val+1 ).change();
        });

        $('.quantity').on('click', '.minus', 
            function(e) {
            $input = $(this).next('input.qty');
            var val = parseInt($input.val());
            if (val > 0) {
                $input.val( val-1 ).change();
            } 
        });
    });
    </script>

it works fine but the problem is when i update any product on cart page it doesn't work anymore. is there any kind of solution? Please correct me if i did anything wrong?
Thanks

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You have the first part correct. Your code will work when loading a page. But in addition to this you need to add an event for the AJAX calls.

I also added .off() so the value wont add itself multiple times after every AJAX call.

<script type="text/javascript">

jQuery(document).ajaxComplete(function(){
    jQuery('.quantity').off('click', '.plus').on('click', '.plus', function(e) {        
        $input = jQuery(this).prev('input.qty');
        var val = parseInt($input.val());
        $input.val( val+1 ).change();
    });



        jQuery('.quantity').off('click', '.minus').on('click', '.minus',
        function(e) {       
        $input = jQuery(this).next('input.qty');
        var val = parseInt($input.val());
        if (val > 1) {
            $input.val( val-1 ).change();
        }
    });
});

</script>
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!