Hide or display button through a ifelse with data from a foreach

Asked

Viewed 293 times

1

Guys I have this code, and the following, I need to print or hide a button according to the result of foreach, example if it is empty I want it to hide the button, if you have any item it shows the button.

    <?php

    foreach( $types_list as $single_type ) {

        $yith_wapo_frontend->printSingleGroupType( $product , $single_type );

    }



    $product_id = yit_get_base_product_id( $product );

    $product_display_price = yit_get_display_price( $product );

    ?>
      </div>

        <button class="btn2" data-dismiss="modal" aria-hidden="true">Concluído</button>

      </div>

    <?php
     $var = $product_id; 

    if( $var >= 1 ) {
    echo "<a href='#myModal' role='button' class='btn' data-toggle='modal'>Quero Personalizar</a>";    
    } else if ( $var = 0 ) {
    echo "<a hr

ef='#myModal' role='button' class='btn' data-toggle='modal' style='display:none'>Quero Personalizar</a>";    
}


?>
  • 1

    The hide/show button is this <button class="btn2" data-dismiss="modal" aria-hidden="true">Concluído</button> ?

  • no, and I want to customize it. Look at if there..

1 answer

1


You can use the function empty php to test if the array has any elements:

if( !empty($types_list) ) { //se não está vazio mostra
    echo "<a href='#myModal' role='button' class='btn' data-toggle='modal'>Quero Personalizar</a>";    
} else { //se está esconde
    echo "<a href='#myModal' role='button' class='btn' data-toggle='modal' style='display:none'>Quero Personalizar</a>";    
}
  • In parts the code was right, in the case If if there I had to take the If ...

  • Thanks for the help Isac!

  • @Brunoroberto yes, thanks for the indication that I hadn’t even noticed that I was there

Browser other questions tagged

You are not signed in. Login or sign up in order to post.