In my functions.php I'm creating a Woocommerce simple hook, in which I'm intending to use javascript:
function mysite_woocommerce_payment_complete( $order_id ) {
$order = wc_get_order( $order_id );
?>
HELLO
<script>
var a =2;
</script>
<?php
}
add_action( 'woocommerce_payment_complete', 'mysite_woocommerce_payment_complete', 10, 1 );
As you can see, inside my function, I'm exiting PHP. But for some reason, everything I'm writing outside of PHP just logs in the console (INSTEAD of and not in addition to executing). In my console I can see
HeLLO
<script>
var a =2;
...
Why does this behaviour occur? And why can't I use javascript inside this hook function?
Thanks in advance