How to show/hide php table rows based on the content of custom fields

You just need to render each section a little more efficiently. Making it look nice with all the fancy spacing won’t pay off when a computer is reading the code (see tab v. space).

So for the ‘Author’ section, which you could apply to more sections, you want to gather all the date first and filter out any empty variables. Then check to see if you have data left. Once you’re sure you have some data, then just loop through it to render it dynamically.

$author_info = array_filter( array (
    'honorificPrefix' => types_render_field( "schema-book-author-honorific-prefix", array () ),
    'givenName'       => types_render_field( "schema-book-author-given-name", array () ),
    'familyName'      => types_render_field( "schema-book-author-family-name", array () ),
    'honorificSuffix' => types_render_field( "schema-book-author-honorific-suffix", array () ),
) );

if ( ! empty( $author_info ) ) {

    echo '<tr><td>Author</td><td><span itemprop="author" itemscope itemtype="http://schema.org/Person">';

    foreach ( $author_info as $prop => $value ) {

        printf( '<span itemprop="%s">%s</span>', $prop, $value );

    }

    echo '</span></td></tr>';
}