How do I hide if no value in php function

Viewed 32

how do i hide the whole "Conditions: " if the field is empty? i cannot seems to figure out and the code i tried are invalid

echo '<span class="sku">Conditions: ' . get_post_meta( $product->id, '_conditions', true ) . '</span>';

Thanks so much!

1 Answers

Maybe try this:

if(!empty(get_post_meta( $product->id, '_conditions', true ))){
    echo '<span class="sku">Conditions: ' . get_post_meta( $product->id, '_conditions', true ) . '</span>';
}
Related