Introduction ↑ Back to Top
The Conditional Tags of both WooCommerce and WordPress can be used in your Template files to change what content is displayed based on what conditions that page matches. For example, you might want to display a snippet of text above the shop page. With the is_shop() Conditional Tag you can.
Since WooCommerce uses custom post types you can use many of WordPress’ own conditional tags too. See: http://codex.wordpress.org/Conditional_Tags.
Warning: You can only use conditional query tags after the posts_selection action hook in WordPress (the wp action hook is the first one through which you can use these conditionals). For themes, this means the conditional tag will never work properly if you are using it in the body of functions.php, i.e. outside of a function.
The Conditions For…
All of the Conditional Tags test to see whether a certain condition is met, and then returns either TRUE or FALSE. The conditions under which various tags output TRUE is listed below.
A WooCommerce page
- Returns true if on a page which uses WooCommerce templates (cart and checkout are standard pages with shortcodes and thus are not included).
The main shop page
- Returns true when on the product archive page (shop).
A product category page
- Returns true when viewing a product category archive.
is_product_category( 'shirts' )
- When the product category page for the ‘shirts’ category is being displayed.
is_product_category( array( 'shirts', 'games' ) )
- When the product category page for the ‘shirts’ or ‘games’ category is being displayed.
A product tag page
- Returns true when viewing a product tag archive
is_product_tag( 'shirts' )
- When the product tag page for the ‘shirts’ tag is being displayed.
is_product_tag( array( 'shirts', 'games' ) )
- When the product tag page for the ‘shirts’ or ‘games’ tags is being displayed.
A single product page
- Returns true on a single product page. Wrapper for is_singular.
The cart page
- Returns true on the cart page.
The checkout page
- Returns true on the checkout page.
Customer account pages
- Returns true on the customer’s account pages.
An ajax request
- Returns true when the page is loaded via ajax.
A working example
The example below shows how you would show different content for different categories.