当前位置:首页-WordPress文章-WooCommerce-正文

WooCommerce 商城插件的条件式标签

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

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

可用的条件式标签

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

下面的列表包含主要的条件式标签,要查看所有条件标记,请访问WooCommerce API Docs

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/

本文原创,作者:萨龙龙,其版权均为4166am金沙信心之选所有。
如需转载,请注明出处:/woocommerce-conditional-tags.html

\u56e0\u4e3aWooCommerce\u4f7f\u7528\u81ea\u5b9a\u4e49pos\u2026@\u8428\u9f99\u7f51\u7edc&appkey=746468751&pic=https:\/\/demo.salongweb.com\/mnews\/images\/default-thumb.jpg&searchPic=true","qq":"https:\/\/connect.qq.com\/widget\/shareqq\/index.html?url=https:\/\/salongweb.com\/woocommerce-conditional-tags.html&title=WooCommerce \u5546\u57ce\u63d2\u4ef6\u7684\u6761\u4ef6\u5f0f\u6807\u7b7e&pics=https:\/\/demo.salongweb.com\/mnews\/images\/default-thumb.jpg&summary=\u53ef\u4ee5\u5728\u6a21\u677f\u6587\u4ef6\u4e2d\u4f7f\u7528WooCommerce\u548cWordPress\u7684\u6761\u4ef6\u5f0f\u6807\u7b7e\uff0c\u4ee5\u6839\u636e\u5339\u914d\u9875\u9762\u7684\u6761\u4ef6\u6765\u663e\u793a\u7684\u7279\u5b9a\u5185\u5bb9\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u80fd\u60f3\u8981\u5728\u5546\u5e97\u9875\u9762\u4e0a\u65b9\u663e\u793a\u4e00\u4e2a\u6587\u672c\u5b57\u6bb5\uff0c\u5c31\u53ef\u4ee5\u4f7f\u7528is_shop()\u6761\u4ef6\u5f0f\u6807\u7b7e\u3002

\u56e0\u4e3aWooCommerce\u4f7f\u7528\u81ea\u5b9a\u4e49pos\u2026&site=\u8428\u9f99\u7f51\u7edc","zone":"https:\/\/sns.qzone.qq.com\/cgi-bin\/qzshare\/cgi_qzshare_onekey?url=https:\/\/salongweb.com\/woocommerce-conditional-tags.html&title=WooCommerce \u5546\u57ce\u63d2\u4ef6\u7684\u6761\u4ef6\u5f0f\u6807\u7b7e&desc=\u53ef\u4ee5\u5728\u6a21\u677f\u6587\u4ef6\u4e2d\u4f7f\u7528WooCommerce\u548cWordPress\u7684\u6761\u4ef6\u5f0f\u6807\u7b7e\uff0c\u4ee5\u6839\u636e\u5339\u914d\u9875\u9762\u7684\u6761\u4ef6\u6765\u663e\u793a\u7684\u7279\u5b9a\u5185\u5bb9\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u80fd\u60f3\u8981\u5728\u5546\u5e97\u9875\u9762\u4e0a\u65b9\u663e\u793a\u4e00\u4e2a\u6587\u672c\u5b57\u6bb5\uff0c\u5c31\u53ef\u4ee5\u4f7f\u7528is_shop()\u6761\u4ef6\u5f0f\u6807\u7b7e\u3002

\u56e0\u4e3aWooCommerce\u4f7f\u7528\u81ea\u5b9a\u4e49pos\u2026&summary=&site=\u8428\u9f99\u7f51\u7edc"}>