skip to Main Content

How could I hide element button in my case if the product is in specific category ?
I have tried

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

</div>

2

Answers


  1. You can apply a condition on the button to not display in the specified category.If you want to do it by style

    <?php if (has_term( "category", "product_cat", $post->ID ) ) { ?>
        <style>
          #buttonid{display:none;}
        </style>
    <?php }?>
    
    <div id="buttonid">
     <button>Save</button>
    </div>
    
    Login or Signup to reply.
  2. You missed php syntax:

    <div id="buttonid"<?php if ( has_term( "category", "product_cat", $post->ID ) ) { echo 'style=" display:none;"'; }?>></div>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search