I work on a plugin and want to add an inline JS script once the place order button is hit on the checkout page (Woocommerce extension). In other words is there a way to add inline JS once wp_enqueue_scripts has already been fired?
1 Answer
i don't know with version you use, but if you wan't load stuff on the initialisation of js you can have it on file using js :
( function( wp ) { your stuff } )( window.wp );
if you really want inline use in php ; https://developer.wordpress.org/reference/functions/wp_add_inline_script/
wp_add_inline_script( 'name_of_the_script_Woocommerce', <script> your thing</script>, 'after_or_before' );
wp_enqueue_scripts
has already been fired? Not sure. I think if you're looking to add inline JS after the enqueuing has already been done, and your theme supports it, you could stick some JS in using thewp_footer
hook. Not ideal, but will get the job done.