Skip to content
Advertisement

In a WordPress template, how can I detect if the current page is the WooCommerce cart or checkout page?

I would like to have a header banner hidden when a user is in the WooCommerce cart or checkout process. Is there a flag or variable that I can check to see if the current page is in either of these WooCommerce sections? I basically want to do something like the following:

if (!is_checkout() && !is_cart()) {
   echo "<div>My Banner</div>";
}

I realize I can make a custom page template for each of these sections, but I just want to add a simple bit of code to my global site header.

Advertisement

Answer

Cart page

is_cart()

Returns true on the cart page.

Checkout page

is_checkout()

Returns true on the checkout page.

You can see more about WooCommerce conditional tags

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement