The intention of my PHP
code below is to display the product GTIN
number when it is available and display a message when it isn't. But regardless of whether or not a GTIN
value exists, it just returns the message.
// https://businessbloomer.com/woocommerce-add-text-add-cart-single-product-page/
add_action( 'woocommerce_single_product_summary', 'custom_data_above_add_to_cart_button', 6 );
function custom_data_above_add_to_cart_button( $product ) {
// https://wordpress.stackexchange.com/a/165757/135006
if ( get_post_meta( $post->ID, 'wccaf_gtin', true ) ) {
echo '<p>'.get_post_meta( $post->ID, 'wccaf_gtin', true ).'</p>';
} else {
echo '<p>GTIN unspecified.</p>';
}
}