Reputation: 1
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 ? :)
Upvotes: 0
Views: 2206
Reputation: 544
This event fire after checkout update
jQuery( document ).on( 'updated_checkout', function() {
//Write code here to fire event
console.log('run');
});
Upvotes: 3
Reputation: 544
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.
Upvotes: 1