Here’s a solution using a [shortcode]
which doesn’t rely on running PHP inside of the content area. Here are the docs for get_post_meta()
which show how that function should be called.
add_shortcode( 'buy_status', 'wpse249289_buy_status' );
function wpse249289_buy_status( $atts ) {
$output="";
if ( ! get_post_meta( get_the_ID(), 'buy_status', true ) ) {
// Post meta value for key buy_status is false
$output .= '<h5 style="text-align: center;display: block;">';
$output .= 'Sorry, this piece is sold.';
$output .= '</h5>';
} else {
// Post meta value for key buy_status is not false
$output .= '<h5 style="text-align: center;display: none;"></h5>'; // Not sure why you'd want to output anything
}
return $output;
}