I use them even more than WordPress conditional tags, but that’s just because I mainly work on WooCommerce stuff like themes and plugins.
They are particularly useful in customizations, so if you want to add some custom features to your site, you should really learn how they work.
If you read some of my previous posts, you probably already noticed some of them in the snippets.
So let’s learn what we have and how we can use them.
Shop page & WooCommerce
The two main conditional tags are
true if the page shown in the main Shop page of your store, that one set in WooCommerce > Settings > Products > Display. It could be useful to show, in example, a specific banner for the shop page only, depending on how you decide to add the banner to your store.
is_woocommerce() instead, is more generic. It returns
true whenever you are on a page that uses a WooCommerce template. Note though that the Cart and Checkout pages are not included, neither those pages where you are only using a WooCommerce shortcode.
The snippet above applies here as well, if you want to show the banner in any WooCommerce page.
There are several conditional tags related to products.
The most obvious is
is_product(). It returns
true if the page shown is a single product page.
But you can also check if you are on a specific product tag or category archive, with
They both accept a parameter, an array of terms or a string, to check if you are on a tag or category archive page for that term.
Other conditional tags
The remaining WooCommerce conditional tags are those needed to check if you are on the cart, checkout and account pages or on an endpoint.
To check if the page shown is the Cart page, you can use
To check if the page shown is the Checkout page instead, use
is_checkout(). This one is particularly useful for customizations for the payment gateways and shipping methods.
If you want to add/edit something only on the page My Account, use
is_account_page(). Useful to print a special message for your customers in their account page.
If you want to do something on an endpoint instead, you can use
is_wc_endpoint(). It accepts parameters to check if you are on a specific endpoint.
In example you could check if you are on the Thank you page by using
is_wc_endpoint( 'order-received' ).
If you want to learn more, you can check this page to know how to use the parameters accepted by these conditional tags.