Skip to content
Advertisement

Include some javascript code in HEAD on WooCommerce Order received

Goal: I need to include an event snippet for specific tracking on the Woocommerce Order Confirmation page (the page immediately following a purchase). I must pass order_id, currency and total to the tracker. Here is the code I’ve written:

JavaScript

This includes the code correctly on the page and passes the relevant info to the tracker. But this code does not appear in the <head> of the page; it appears in the body. Per instructions this code must be placed in the <head>.

I have not found a snippet plugin that allows for this kind of control. Is there another way I can achieve this?

If I were to include this code on all pages in the <head> but wrap it in an if statement that checks for the url, /checkout/order-received/{order-id}/ and fires if true, is that possible or there another way?

Advertisement

Answer

You can use the following to inject your Javascript code in the head on “Order received” page:

JavaScript

Code goes in functions.php file of the active child theme (or active theme). It should work.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement