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

1

I have this code, and the following, I need to print or hide a button according to the foreach result, example if it is empty I want it to hide the button, if there is 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>";    
}


?>
    
asked by anonymous 26.07.2017 / 00:33

1 answer

1

You can use the empty of php function 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>";    
}
    
26.07.2017 / 00:59