可以在模板文件中使用WooCommerce和WordPress的条件式标签，以根据匹配页面的条件来显示的特定内容。例如，您可能想要在商店页面上方显示一个文本字段，就可以使用`is_shop()`条件式标签。

因为 WooCommerce 使用自定义post类型，所以您也可以使用许多 WordPress 的条件式标签。

### 可用的条件式标签

所有条件式标签测试条件是否满足，都是返回`true` 或`false`，标签输出`true` ，条件中的内容将在下面输出。

下面的列表包含主要的条件式标签，要查看所有条件标记，请访问[WooCommerce API Docs](https://document.woocommerce.com/wc-apidocument/index.html)。

### WooCommerce 页面

`is_woocommerce()`，如果使用在WooCommerce模板的页面(购物车和结算是带有短代码的标准页面，因此不包括在内)则返回`true`。

### 主要商品页面

`is_shop()`，如果使用在WooCommerce模板的归档页面（包括商城首页）则返回`true`。

### 产品分类页面

`is_product-category()`，如果使用在WooCommerce模板的产品分类归档页面则返回`true`。

`is_product-category('shirts')`，如果分类为『shirts』则返回`true`。

`is_product-category(array( 'shirts', 'games' ))`，如果分类为『 shirts 或者 games 』则返回`true`。

### 产品标签页面

`is_product-tag()`，如果使用在WooCommerce模板的产品标签归档页面则返回`true`。

`is_product-tag('shirts')`，如果标签为『shirts』则返回`true`。

`is_product-tag(array( 'shirts', 'games' ))`，如果标签为『 shirts 或者 games 』则返回`true`。

### 商品文章页面

`is_product()`，如果使用在WooCommerce模板的产品文章页面则返回`true`。

### 购物车页面

`is_cart()`，如果使用在WooCommerce模板的购物车页面则返回`true`。

### 结算页面

`is_checkout()`，如果使用在WooCommerce模板的结算页面则返回`true`。

### 我的帐户页面

`is_account_page()`，如果使用在WooCommerce模板的我的帐户页面则返回`true`。

### 端点页面

`is_wc_endpoint_url()`，如果使用在WooCommerce模板的端点页面则返回`true`。

`is_wc_endpoint_url('order-pay')`，如果使用在WooCommerce模板的付款页面则返回`true`。

`is_wc_endpoint_url('order-received')`，如果使用在WooCommerce模板的已收到订单页面则返回`true`。

`is_wc_endpoint_url('view-order')`，如果使用在WooCommerce模板的查看订单页面则返回`true`。

`is_wc_endpoint_url('edit-account')`，如果使用在WooCommerce模板的编辑帐户页面则返回`true`。

`is_wc_endpoint_url('edit-address')`，如果使用在WooCommerce模板的编辑地址页面则返回`true`。

`is_wc_endpoint_url('lost-password')`，如果使用在WooCommerce模板的忘记密码页面则返回`true`。

`is_wc_endpoint_url('customer-logout')`，如果使用在WooCommerce模板的用户登出页面则返回`true`。

`is_wc_endpoint_url('add-payment-method')`，如果使用在WooCommerce模板的添加付款方式页面则返回`true`。

AJAX 请求页面

`is_ajax()`，如果使用在AJAX请求页面则返回`true`。

原文地址：https://document.woocommerce.com/document/conditional-tags/