skip to Main Content

am trying to do somthing like : Woocommerce update checkout ajax! am building a multistep form for my client where the customer is adding a product in the cart using ajax . I need to update the checkout when a product is added into the cart . I tried to do an onclick function so when the user add the product in the cart the checkout step update without refreshing the page :

jQuery('#test').on('click',function(){
    $( document.body ).trigger( 'update_checkout' );
})

but its not working and i feel like am missing somthing obvious …. Any tips ? 🙂

2

Answers


  1. Your code is correct you have to replace $ with jQuery

     //Paste this code in theme footer.php file and check it on checkout page
    <?php if (is_checkout()) { ?>
      <button id="test">Click here to update checkout</button>
      <script type="text/javascript">
        jQuery(document).ready(function(){
          jQuery('#test').on('click',function(){ alert("pp");
            jQuery( document.body ).trigger( 'update_checkout' );
          });
        });
      </script>
    <?php } ?>
    

    The code is tested everything is working fine.

    Login or Signup to reply.
  2. This event fire after checkout update

    jQuery( document ).on( 'updated_checkout', function() { 
    
        //Write code here to fire event 
        console.log('run');
    
    });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search