
I’m having trouble finalizing the specifications section of each product on my site. I’m successfully pulling in all of the field groups that I need in the table shown on this page just below the product image. https://staging-casterconcepts.kinsta.cloud/product/4×2-t-r-95-polyurethane-caster-wheel-3/
Where I’m having issues is finding a way to omit the PRJ Link field without it breaking my alternating cell color styling. I can’t seem to find any references where I can pull all and only the fields that have data and omit any that I would like, and for the table to keep an alternating row color. This is how I’m pulling in the data, any links to examples or suggestions would be greatly appreciated.
<!– Product Specs –>
<div class=”row”>
<h2 class=”prod-bb”><?php esc_html_e( ‘Specifications’ ); ?></h2>
</div>
<div class=”row”>
<?php
//$id = $product->get_id();
$fields = get_field_objects(); if( $fields ): ?>
<?php foreach( $fields as $field ): ?>
<?php if( $field[‘value’] ): ?>
<div class=”col-xl-6 spec-col”>
<?php echo $field[‘label’]; ?>: <?php echo $field[‘value’]; echo $field[‘append’]; ?>
</div>
<?php endif; ?>
<?php endforeach; ?>
<div class=”col-xl-6 spec-col”><?php esc_html_e( ‘SKU:’ ); ?> <?php echo $product->get_sku(); ?></div>
<div class=”col-xl-6 spec-col”><span class=”<?php if ( $product->get_weight() == ” ) { echo ‘d-none’; } ?>”><?php esc_html_e( ‘Caster Weight:’ ); ?> <?php echo $product->get_weight(); ?> <?php esc_html_e( ‘lbs’ ); ?></span></div>
<?php endif; ?>
</div><!– #end product specs –>
For alternating rows, should the row tag not be in the loop and the alternative class be applied to that?
That way, you could also wrap the if( $field[‘value’] ): around the row, so shouldn’t break if a row returns empty.