首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WooCommerce IF语句不工作

WooCommerce IF语句不工作
EN

WordPress Development用户
提问于 2020-01-14 00:45:00
回答 1查看 606关注 0票数 1

我试图使用WooCommerce条件标记只将模板包含到特定的产品页面中。https://docs.woocommerce.com/document/conditional-tags/

然而,我的声明不起作用,它们显示在所有的页面上。我不想在特定类别及其产品页面中显示我的模板:

代码语言:javascript
复制
<?php 
 // Show in Shop Page OR NOT in Products IDs 15852,15859,15863,15866 OR NOT Category Archive Gift Cards

 if ( is_shop() || !is_product(array( 15852,15859,15863,15866 )) ||  !is_product_category( 'gift-cards' )) 
 { 
      get_template_part('my-template'); 
 } 
 ?>

我也尝试过相反的方法:

代码语言:javascript
复制
<?php 
if ( is_product(array('gift-card-25','gift-card-50','gift-card-75','gift-card-100')) ) 
{ 
    get_template_part('my-template'); 
} 
?>

你能告诉我怎么让它起作用吗?

我们的网站:https://grindersforlife.com/shop

谢谢!

EN

回答 1

WordPress Development用户

发布于 2020-01-15 07:20:48

解决我的问题的办法是使用:

has_term( 'the-cat-I-want-to-display', 'product_cat' ) || is_product_category( 'the-cat-I-want-to-display' )

这个成功了。谢谢大家的帮助!

票数 1
EN
页面原文内容由WordPress Development提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://wordpress.stackexchange.com/questions/356311

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档