Using an “IF” statement based on the existence of custom field

I think this should help

if ( get_post_meta( $post->ID, 'name_of_the_custom_field', true ) ) :
    // Do something
endif;