0

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 ? :)

Malik
  • 1
  • 1

2 Answers2

2

This event fire after checkout update

jQuery( document ).on( 'updated_checkout', function() { 

    //Write code here to fire event 
    console.log('run');

});
gaurav sharma
  • 534
  • 2
  • 6
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.

gaurav sharma
  • 534
  • 2
  • 6
  • thanks i managed to update the checkout with ajax but now i have an other problem aha... it shows the chekout but it wont load the necessary stripe script to display the card field.... – Malik Nov 21 '21 at 14:22
  • ok I have a solution check the next post jQuery( document ).on( 'updated_checkout', function() { //Write code here to fire event console.log(''); }); – gaurav sharma Nov 22 '21 at 06:22