Home » Php » Target checkout page but not order-received page in Woocommerce

Target checkout page but not order-received page in Woocommerce

Posted by: admin September 25, 2018 Leave a comment

Questions:

I’m linking some .js in my functions.php this way:

if(get_query_var('pagename')==='checkout') {
    wp_enqueue_script('script', 'my.js', array('jquery'), 1.1, true);
}

my.js is where i check for some checkout form input fields.
Now i see that my.js is linked also in the order-received page (that is a ‘sub-page’ of the checkout page, i know!), and this causes some errors because the checkout form isn’t there anymore.

How to conditionally execute some code in the checkout page but not in order-received one?

Thanx.

Answers: