Custom fields displayed with labels & values in table?

Hi,

I’m new with PHP and currently really struggling to recreate a table with Advanced Custom Feilds.

The layout of fields with labels on the left and fields on the right.

I’m trying to add ACF to better assemble WooCommerce singe product page after tabs. Post type is set to product and values are inputted - but I can’t for the life of me undestand how to display both label and value while leave empty if blank value.

Added to functions.php but I’ve got a feeling I’m either close or a mile off, but at least I’ve tried / pulled my hair out.

CODE:

add_action( 'woocommerce_after_single_product', 'property_overview_field', 3 );
  
function property_overview_field() { ?>
 
<?php 

<?php if ( $guide_price != '' || $property_category != '' || $property_type != '' || $bedroom != '' || $bathroom != '' || $listing_status != '' || $city != '' || $county != '' || $location != '' || $epc_rating !='' ) { ?>
                    
<div class="property-overview">

    <ul>
        <?php
            if( $guide_price != '') { ;?>
        <li>
            <?php echo $field['label']; ?>:
            <strong><?php echo $field['value']; ?></strong>
        </li>
         <?php
            if( $property_category != '') { ;?>
        <li>
            <?php echo $field['label']; ?>:
            <strong><?php echo $field['value']; ?></strong>
        </li>
         <?php
            if( $property_type != '') { ;?>
        <li>
            <?php echo $field['label']; ?>:
            <strong><?php echo $field['value']; ?></strong>
        </li>
         <?php
            if( $bedroom != '') { ;?>
        <li>
            <?php echo $field['label']; ?>:
            <strong><?php echo $field['value']; ?></strong>
        </li>
    </ul>
</div>
<?php }		
}

CSS

CSS
.property-overview{margin: 0px 0px 30px 0px;padding: 0px;display: flex;} .property-overview ul {background: #fff;box-shadow: 0 2px 4px rgba(0,0,0,.1);padding: 12px 20px !important; width: 100%;margin-top: 0; margin-bottom: 10px;list-style: none !important;} .single-pro_estate .property-overview li {border-bottom: 1px dashed #ddd;clear: left;float: left;line-height: 40px; width: 48%;} .property-overview ul li span{ font-weight:600;} .property-overview li strong.emphasize {color: #666;font-weight: 600;} .property-overview li strong{ float:right;} .property-overview li:nth-child(2n) { float: right; clear: right;}

Any help would be much apperciated.

I would look into using CSS grids or CSS flex to do this.

An example of what I’m talking about.

CSS

.cards {
    width: 60em;
    padding: 0;
    margin: 1.250em auto;
}

.card {
    margin-bottom: 1em;
}

.card a {
    color: #0d0d0d;
    text-decoration: none;
    border: 1px transparent;
    transition: all .2s;
}

.card a .cms_heading {
    background-color: #f1f1f1;
    padding: 1.250em;
}

.card a .cms_content {
    background-color: #f1f1f1;
    font-family: 'Rubik', sans-serif;
    font-size: 1.0em;
    line-height: 1.8;
    padding: 1.250em;
}

@supports (grid-area: auto) {
    @media screen and (min-width: 27em) {
        /* Main Site Grid with sliding navigation */
        .site {
            position: relative;
            left: -14em;
            overflow-x: hidden;
            display: grid;
            grid-template-columns: 15em calc(100% - 1em);
            grid-template-areas: "nav header" "nav main" "nav sidebar" "nav footer";
            transition: left .6s;
        }
        .masthead {
            grid-area: header;
        }
        .main-area {
            grid-area: main;
        }

        .card a {
            display: grid;
            grid-template-columns: fit-content(18.5em) 1fr;
            grid-template-areas: "thumbnail heading" "thumbnail content";
            justify-content: space-around;
        }

        .cms_heading {
            grid-area: heading;
        }

        .cms_content {
            grid-area: content;
        }

    }
}

The HTML

<ul class="cards">
    <?php
    foreach ($cms as $record) {
        echo '<li class="card">' . "\n";
        echo '<a href="/display/' . urldecode($record['id']) . '">' . "\n";
        echo '<div class="cms_heading">' . "\n";
        echo '<h2>' . $record['heading'] . '</h2>' . "\n";
        echo '<p class="byline">by ' . $record['author'] . ' on ' . CMS::styleDate($record['date_added']) . '</p>' . "\n";
        echo '</div>' . "\n";
        echo '<p class="cms_content">' . nl2br(CMS::intro($record['content'], 200)) . '</p>' . "\n";
        echo '</a>' . "\n";
        echo '</li>' . "\n";
    }
    ?>
</ul>

Using Grids or Flex you basically can have any style you want and you can easily change the styling compared to what you had to do using CSS that deals with floats, padding and other crazy styling.

Thanks Strider for taking the time to reply. I appreciate that.

Sorry, to be thick but I’m unsure how I can adopt that way for my setup with advanced custom fields plugin. This field group is one of many which is assembled to post type ~> products for our shop.

Sponsor our Newsletter | Privacy Policy | Terms of Service