【问题标题】:Hide the element if product is in a specific category如果产品属于特定类别,则隐藏元素
【发布时间】:2021-09-12 12:36:17
【问题描述】:

如果产品属于特定类别,我该如何隐藏元素按钮? 我试过了

<div id="buttonid"  if ( has_term( "category", "product_cat", $post->ID ) ) { echo 'style="display:none;"' }?>></div>

</div>

【问题讨论】:

  • 这里实际上并没有样式化任何东西,你只是将文本内容写入了一个div元素。
  • 这能回答你的问题吗? Show Hide div if, if statement is true
  • 简单查询可以解决你的问题where category != 'product_cat'或者数组过滤。

标签: php wordpress


【解决方案1】:

您可以在按钮上应用一个条件,使其不显示在指定的类别中。如果您想按样式进行操作

<?php if (has_term( "category", "product_cat", $post->ID ) ) { ?>
    <style>
      #buttonid{display:none;}
    </style>
<?php }?>

<div id="buttonid">
 <button>Save</button>
</div>

【讨论】:

    【解决方案2】:

    你错过了 php 语法:

    <div id="buttonid"<?php if ( has_term( "category", "product_cat", $post->ID ) ) { echo 'style=" display:none;"'; }?>></div>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-29
      • 2015-10-07
      • 2015-10-10
      • 2022-08-24
      • 1970-01-01
      相关资源
      最近更新 更多