avatar
2 minutes read

Run jQuery after WooCommerce AJAX cart update

WooCommerce:

I have some jQuery that heaps on document.ready that impacts the amount input box. Works perfectly.

My issue is that when I update the truck/erase thing, the jQuery needs to run again in light of the fact that the AJAX call kills it (revives it). Is there some snare/channel I can add that will re-pursue my content again a truck update? Ive looked and can't track down anything (or perhaps I'm not mindful of what I'm searching for).

Thank you!!!!

Solutions

The WooCommerce scripts have a few custom jQuery occasions worked in. Your own content can pay attention to these occasions and run your own code when they are set off. The clearest one for your case may be updated_cart_totals however updated_wc_div could likewise be useful, I don't know without testing. Tried and works.

$( document.body ).on( 'updated_cart_totals', function(){
    //re-do your jquery
});

Jan 2024 Update: I accept this won't work with the Truck/Checkout blocks, however just with the conventional truck/checkout shortcodes.

Comments