{"id":2476,"date":"2015-03-25T11:08:37","date_gmt":"2015-03-25T15:08:37","guid":{"rendered":"http:\/\/codebangers.com\/?p=2476"},"modified":"2015-03-25T11:08:37","modified_gmt":"2015-03-25T15:08:37","slug":"woocommerce-conditional-tags","status":"publish","type":"post","link":"https:\/\/codebangers.com\/woocommerce-conditional-tags\/","title":{"rendered":"Woocommerce Conditional Tags"},"content":{"rendered":"<h1 id=\"section-1\">Introduction<\/h1>\n<p>The Conditional Tags of both WooCommerce and WordPress\u00a0can be used in your Template files to change what content is displayed based on what\u00a0<em>conditions<\/em>\u00a0that page matches. For example, you might want to display a snippet of text above the shop page. With the is_shop()\u00a0Conditional Tag you can.<\/p>\n<p>Since WooCommerce uses custom post types you can use many of WordPress\u2019 own conditional\u00a0tags too. See:\u00a0<a href=\"http:\/\/codex.wordpress.org\/Conditional_Tags\" target=\"_blank\" rel=\"noopener\">http:\/\/codex.wordpress.org\/Conditional_Tags<\/a>.<\/p>\n<p><strong>Warning: You can only use conditional query tags after the\u00a0<em>posts_selection\u00a0<\/em><a title=\"Plugin API\/Action Reference\" href=\"http:\/\/codex.wordpress.org\/Plugin_API\/Action_Reference#Actions_Run_During_a_Typical_Request\" target=\"_blank\" rel=\"noopener\">action hook<\/a>\u00a0in WordPress (the\u00a0<em>wp<\/em>\u00a0action 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.<\/strong><\/p>\n<h2>The Conditions For\u2026<\/h2>\n<p>All of the Conditional Tags test to see whether a certain condition is met, and then returns either TRUE or FALSE.\u00a0<strong>The conditions under which various tags output TRUE is listed below<\/strong>.<\/p>\n<h3>A WooCommerce page<\/h3>\n<dl>\n<dt><code>is_woocommerce()<\/code><\/dt>\n<dd>Returns true if on a page which uses WooCommerce templates (cart and checkout are standard pages with shortcodes and thus are not included).<\/dd>\n<\/dl>\n<h3>The main shop page<\/h3>\n<dl>\n<dt><code>is_shop()<\/code><\/dt>\n<dd>Returns true when on the product archive page (shop).<\/dd>\n<\/dl>\n<h3>A product category page<\/h3>\n<dl>\n<dt><code>is_product_category()<\/code><\/dt>\n<dd>Returns true when viewing a product category archive.<\/dd>\n<dt><code>is_product_category( 'shirts' )<\/code><\/dt>\n<dd>When the product category page for the \u2018shirts\u2019 category is being displayed.<\/dd>\n<dt><code>is_product_category( array( 'shirts', 'games' ) )<\/code><\/dt>\n<dd>When the product category page for the \u2018shirts\u2019 or \u2018games\u2019 category is being displayed.<\/dd>\n<\/dl>\n<h3>A product tag page<\/h3>\n<dl>\n<dt><code>is_product_tag()<\/code><\/dt>\n<dd>Returns true when viewing a product tag archive<\/dd>\n<dt><code>is_product_tag( 'shirts' )<\/code><\/dt>\n<dd>When the product tag page for the \u2018shirts\u2019 tag is being displayed.<\/dd>\n<dt><code>is_product_tag( array( 'shirts', 'games' ) )<\/code><\/dt>\n<dd>When the product tag page for the \u2018shirts\u2019 or \u2018games\u2019 tags is being displayed.<\/dd>\n<\/dl>\n<h3>A single product page<\/h3>\n<dl>\n<dt><code>is_product()<\/code><\/dt>\n<dd>Returns true on a single product page. Wrapper for is_singular.<\/dd>\n<\/dl>\n<h2>The cart page<\/h2>\n<dl>\n<dt><code>is_cart()<\/code><\/dt>\n<dd>Returns true on the cart page.<\/dd>\n<\/dl>\n<h3>The checkout page<\/h3>\n<dl>\n<dt><code>is_checkout()<\/code><\/dt>\n<dd>Returns true on the checkout page.<\/dd>\n<\/dl>\n<h3>Customer account pages<\/h3>\n<dl>\n<dt><code>is_account_page()<\/code><\/dt>\n<dd>Returns true on the customer\u2019s account pages.<\/dd>\n<\/dl>\n<h3>An ajax request<\/h3>\n<dl>\n<dt><code>is_ajax()<\/code><\/dt>\n<dd>Returns true when the page is loaded via ajax.<\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>Introduction The Conditional Tags of both WooCommerce and WordPress\u00a0can be used in your Template files to change what content is displayed based [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":955,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[137,3],"tags":[273,274,272],"class_list":["post-2476","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-woocommerce","category-wordpress","tag-is_product","tag-is_product_category","tag-is_shop"],"_links":{"self":[{"href":"https:\/\/codebangers.com\/wp-json\/wp\/v2\/posts\/2476","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codebangers.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codebangers.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codebangers.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/codebangers.com\/wp-json\/wp\/v2\/comments?post=2476"}],"version-history":[{"count":1,"href":"https:\/\/codebangers.com\/wp-json\/wp\/v2\/posts\/2476\/revisions"}],"predecessor-version":[{"id":2477,"href":"https:\/\/codebangers.com\/wp-json\/wp\/v2\/posts\/2476\/revisions\/2477"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/codebangers.com\/wp-json\/wp\/v2\/media\/955"}],"wp:attachment":[{"href":"https:\/\/codebangers.com\/wp-json\/wp\/v2\/media?parent=2476"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codebangers.com\/wp-json\/wp\/v2\/categories?post=2476"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codebangers.com\/wp-json\/wp\/v2\/tags?post=2476"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}