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.
Unfortunately you can’t just copy and paste JavaScript in the checkout page… you need a workaround!
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!
PHP Snippet: Add Script @ Checkout Page – WooCommerce
/**
* @snippet Print Script @ Checkout Footer - WooCommerce
* @how-to Get CustomizeWoo.com FREE
* @author Rodolfo Melogli
* @testedwith WooCommerce 5
* @community https://businessbloomer.com/club/
*/
add_action( 'wp_footer', 'bbloomer_add_jscript_checkout', 9999 );
function bbloomer_add_jscript_checkout() {
global $wp;
if ( is_checkout() && empty( $wp->query_vars['order-pay'] ) && ! isset( $wp->query_vars['order-received'] ) ) {
echo '<script>paste your script here!</script>';
}
}
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!