Execute JavaScript in WordPress Hook

I’m afraid you can’t do that. Cause in browser JavaScript works on DOM. And this woocommerce_checkout_order_processed hook will be fired before the DOM loads. So there is no way you can execute this code on firing this hook.

Now there are two solutions I got-

  1. Make it Ajaxified. So you don’t need to reload the DOM and you can execute JavaScript on the DOM.

  2. Second solution is relatively easy but not full proof. As far I understood there should be button by pressing that the order should be processed, right? So you can track this button activity and alert on this activity.