在 wordpress 网站上,商店元数据通过带有以下代码的附加字段显示:
add_action( 'woocommerce_product_meta_end', 'art_get_text_field_before_add_card' );
function art_get_text_field_before_add_card() {
global $post;
?>
<span class="text-field">
Shelf life: <a><?php echo get_post_meta( $post->ID, '_custom_product_text_field', true ); ?> m.</a><br><br>
Volume: <a><?php echo get_post_meta( $post->ID, '_custom_product_text_field2', true ); ?> gr.</a>
</span>
<?php
}
您能否告诉我如何改进代码,以便仅在填充元数据(_custom_product_text_field 和 _custom_product_text_field2)时才在网站上显示“保质期”和“体积”行?