Support

Account

Home Forums Front-end Issues Display all checkbox options and apply class to those that are checked Reply To: Display all checkbox options and apply class to those that are checked

  • Dang I was so close, thank you! That seems to solve the error I was getting and it’s displaying the checkbox labels now, but it’s also displaying most of the classes as “unavailable” when they should be “available”.

    This one shows only one class as “available” when it should be all 7.

    <?php 
    $tier = get_field('tier');
    $values = $tier['available_features'];
    $field = get_field_object('tier_available_features');
    $choices = $field['choices']; 
    ?>
    
    <?php foreach($choices as $choice => $label) : ?>
    <?php foreach ( $values as $value ) : ?>
    <?php if( $value['value'] == $choice ) {		
        $status = 'available';
        }
        else {
        $status = 'unavailable';
        } ?>
    <?php endforeach; ?>
        <li class="<?php echo $status;?>"><?php echo $label;?></li>
    <?php endforeach;?> 

    This version lists the checkbox labels correctly but marks them all with the “unavailable” class.

    <?php 
    $tier = get_field('tier');
    $values = $tier['available_features'];
    $field = get_field_object('tier_available_features');
    $choices = $field['choices']; 
    ?>
    
    <?php foreach($choices as $value => $label) : ?>
    <?php if (in_array($value, $values)) {
        $status = 'available';
        }
        else {
        $status = 'unavailable';}?>
    							
    	<li class="<?php echo $status;?>"><?php echo $label;?></li>
    							
    <?php endforeach;?>

    What am I missing here to get it to appropriately return the value of the checkbox?