How to add custom script to the thank you page
-
Hi,
I’m currently using Facebook Pixel to track traffic on my website. I was instructed to add a script to the header of the thank you page after checkout. However, my website doesn’t have a physical “Thank You” pageāit’s just a link like this:
/checkout/order-received/22942/?key=wc_order_1SjsyhGBZRPh5
Could you please guide me on how to insert the script into the thank you page?
I added the following code to the functions.php file. I’m unsure if this is the correct approach, or if there might be a better solution you can suggest:
function add_facebook_pixel_script() {
if ( is_order_received_page() ) {
?>
<!– Meta Pixel Code –>
script here
<!– End Meta Pixel Code –>
<?php
}
}
add_action(‘wp_head’, ‘add_facebook_pixel_script’);
Hello,
The Most Easy way is to add it using a free plugin https://wordpress.org/plugins/insert-headers-and-footers/
If you want to edit the header.php file directly then you need to copy the header.php file from the main theme to the child theme and then try adding the code in it.
You can read the following article for further help:
https://www.wpbeginner.com/plugins/how-to-add-header-and-footer-code-in-wordpress/
Best Regards.