如果字段为空,则不要在列表中显示自定义字段

Don't display a custom field in a list if the field is empty

早上好。 我已经设置了自定义字段修改列表 function.php。一切正常,但我想在字段为空时隐藏起来。我已经阅读了很多关于它的帖子,但我无法摆脱我的问题。

这是我的 php 代码:

   // Show advanced custom fields in product detail page
add_action( 'woocommerce_single_product_summary', "ACF_product_content", 26 );
 

function ACF_product_content(){

 
  if (function_exists('the_field')){
    echo '<b>MATERIA: </b>';
    the_field('materia'); 
echo "<br />";
    echo '<b>FECHA DE EDICIÓN: </b>';
    the_field('fecha_de_edicion');
echo "<br />";
echo '<b>LUGAR DE EDICIÓN: </b>';
    the_field('lugar_de_edicion');
echo "<br />";
echo '<b>ISBN: </b>';
    the_field('isbn');
echo "<br />";
echo '<b>ISBN DIGITAL: </b>';
    the_field('isbn_digital');
echo "<br />";
echo '<b>ENCUADERNACIÓN: </b>';
    the_field('encuadernacion');
echo "<br />";
echo '<b>INTERIOR: </b>';
    the_field('interior');
echo "<br />";
echo '<b>MEDIDAS: </b>';
    the_field('medidas');
echo "<br />";
echo '<b>NÚMERO DE PÁGINAS: </b>';
    the_field('numero_de_paginas');
echo "<br />";
echo '<b>IDIOMA: </b>';
    the_field('idioma');
echo "<br />";
echo '<b>CÓDIGOS IBIC: </b>';
    the_field('ibic');
  }
  
} 

任何人都可以帮我隐藏其中一个字段(如果它是空的)? 谢谢

改用get_field,然后使用条件检查字段是否不为空,然后echo检查字段。

示例:

$materia = get_field('materia');
if($materia) {
    echo '<b>MATERIA: </b>';
    echo $materia;
}