WooCommerce: How to Add Scripts to the Checkout Page
A client needed to add her SSL Logo Seal to the checkout page. The problem is that the code she was given had also a JS part, together with a bunch of HTML.
In this article, we will learn about wp_footer, a handy WordPress hook to print anything inside the footer, a bit of conditional logic to target the WooCommerce checkout page only (and therefore excluding the Thank You Page and Order Pay Page), and how to print HTML inside a PHP function. Enjoy!
You can place PHP snippets at the bottom of your child theme functions.php file (delete "?>" if you have it there). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such files - if you need more guidance, please take a look at my free video tutorial "Where to Place WooCommerce Customization?"
Does this snippet (still) work?
Please let me know in the comments if everything worked as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting on PHP 7.3.
Check out these free video tutorials. You can learn how to customize WooCommerce without unnecessary plugins, how to properly configure the WooCommerce plugin settings and even how to master WooCommerce troubleshooting in case of a bug!
Business Bloomer Founder
Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza.
6 thoughts on “WooCommerce: How to Add Scripts to the Checkout Page”
How much trouble is it to have your web designer add “code” (and have a number or word or numbers and letters)
to your check out page. I need the businesses working with me to have a code so that when a customer buys from
them, it will tell them that the customer came to them through my web page.
Hello Ellie, thanks for your comment! I recommend you take a look at this tutorial: https://businessbloomer.com/woocommerce-add-custom-checkout-field-php/
Thanks alot for this snippet . However, should this be added in the functions.php?
Vishay, yes, positive 🙂 Place it in your current theme’s functions.php file. Tutorial here:
Thanks this was really helpful. I have my own user-registration form added to this checkout (by copying and overriding the form-checkout.php WC template. I needed to copy over the email address from one field to another, this was perfect for that, thanks!
Thanks for your feedback Gerry!