I am using woocommerce with some custom code to add more details on the cart object when it's submitted to the db.

This works fine, now I am afater a way to clear the localstorage after the order has correctly being placed.

I was thinking about hooking into 'woocommerce_thankyou' with something like this:

add_action( 'woocommerce_thankyou', 'callback', 10, 1 );
   function callback(){
   echo "test";

but the problem is that ideally, I need to run a javascript function from within the callback function to properly clear my localstorage and I'm not sure what's the best way to do it.

I know how to call this functions the other way around (frontend call's backend) but I don't know how backend can call frontend (if it even does in any way)

Thanks for any suggestion


Can't you just put the JS code in the "Thank you" page template? You could use a custom page (e.g. using a module like this https://wordpress.org/plugins/custom-thank-you-page-for-woocommerce/), and then attach custom JS code to that page (e.g. using a module like this https://wordpress.org/plugins/custom-css-js/ ).

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.