- What is_checkout() Checks
- Syntax and Return Value
- When to Call is_checkout()
- Example 1: Keep Checkout Out of Search Engines
- Example 2: Add a Checkout-Only Body Class
- Common Mistakes
- Related WooCommerce Conditional Tags
- FAQs About is_checkout()
- Is is_checkout() the same as is_checkout_pay_page()?
- Does is_checkout() work with the block-based checkout?
- Can I call is_checkout() in functions.php?
- Why does is_checkout() return false on my checkout page?
- Conclusion
Checkout is the most sensitive page in a WooCommerce store. Code that changes headers, scripts, or indexing should run there and nowhere else, and you need a reliable way to check.
The woocommerce is_checkout function, written as is_checkout(), gives you that check. It returns true on checkout and false on the rest of the site. This guide covers what it matches, how timing affects it, and two examples you can paste into a child theme or a site plugin.
What is_checkout() Checks
is_checkout() is a WooCommerce conditional tag. It returns true when the current request shows the checkout page you set in WooCommerce settings, under the Advanced tab, Page setup section.
Other checkout-related URLs, such as the order pay page, can also count as checkout. Test those URLs on your store if your code depends on exact behavior for them.
Syntax and Return Value
- Arguments: none.
- Return value:
trueon the checkout page, otherwisefalse. - Where to use it: inside hooks that run after the main query is set up.
When to Call is_checkout()
The function relies on the main query, which WordPress sets up after the init hook. A call made too early, such as in functions.php at file load, returns false even on the checkout page.
Use one of these hooks:
- wp fires after the main query is ready, so every conditional tag works.
- wp_head fires while the page head is built, which suits meta tags and robots output.
- wp_enqueue_scripts fires before the footer scripts load, which suits assets.
Tip: If is_checkout() returns false on your checkout page, confirm that the page is set as the Checkout page in WooCommerce. A custom page with the checkout shortcode is not enough on its own.
Example 1: Keep Checkout Out of Search Engines
Checkout pages hold no content worth ranking, so many stores mark them as noindex. WordPress 5.7 and later pass robots directives through the wp_robots filter, which is the clean place to do this.
<?php
add_filter( 'wp_robots', 'my_noindex_checkout' );
function my_noindex_checkout( $robots ) {
if ( is_checkout() ) {
$robots['noindex'] = true;
}
return $robots;
}The filter runs in the page head, where is_checkout() already returns the correct value. Check the output with your browser’s view-source tool and look for a robots meta tag that contains noindex.
Example 2: Add a Checkout-Only Body Class
Body classes let you adjust the checkout layout in CSS without touching the template. This filter adds a class only on checkout, so one stylesheet can serve the whole site.
<?php
add_filter( 'body_class', 'my_checkout_body_class' );
function my_checkout_body_class( $classes ) {
if ( is_checkout() ) {
$classes[] = 'my-checkout-page';
}
return $classes;
}Target the class in CSS, for example .my-checkout-page .woocommerce-checkout-review-order, to change the order summary without affecting the cart.
Common Mistakes
- Calling it too early. A check in
initor at file load returns false. Move the call into a hook that runs afterwp. - Using it for the cart. The cart has its own check, is_cart(). Mixing the two produces rules that never match.
- Assuming it covers every checkout URL. Endpoints such as the order pay page need a separate test before you rely on the result.
- Using a custom checkout page without the setting. The function checks the page WooCommerce stores, so an unlinked page returns false.
Related WooCommerce Conditional Tags
Checkout rules often pair with field changes. If you hide or reorder fields, read the guide on WooCommerce checkout fields. For the order confirmation step, see the guide on the order received page. The other page checks are covered in the guides on is_cart(), is_shop(), is_account_page(), and is_product().
FAQs About is_checkout()
Is is_checkout() the same as is_checkout_pay_page()?
No. is_checkout_pay_page() is narrower. It checks only the order pay page, while is_checkout() covers the main checkout page and related checkout URLs.
Does is_checkout() work with the block-based checkout?
Yes, as long as the page is set as the Checkout page in WooCommerce settings. Test on a staging copy first if you use a custom checkout template.
Can I call is_checkout() in functions.php?
You can, but only inside a hook that runs after the main query is ready, such as wp or wp_head. A direct call at file load returns false.
Why does is_checkout() return false on my checkout page?
The most common cause is that the page is not set as the Checkout page in WooCommerce settings. Set it there, then clear your caches and check again.
Conclusion
is_checkout() gives you a dependable check for the checkout page. Use it inside wp or wp_head, and keep checkout-only rules narrow so they do not affect the rest of the store.
If you need checkout changes built and tested for your store, hire a WooCommerce developer or send your requirements through the application form.
