Php 类别分类法(商业产品)

Php 类别分类法(商业产品),php,wordpress,categories,Php,Wordpress,Categories,我在Woocommerce产品中注册了分类法 在ACF的帮助下,我展示了产品类别下的分类法 因此,在每个产品类别中,我都可以很好地选择分类法并在更新时保存它们 现在,我想在single-product.php和archive-product.php中显示选定的分类法。做不到,。。。几个小时 我通过以下方式在帖子/页面类型上很好地实现了这一点: <?php $term_list = wp_get_post_terms($post->ID, 'materiali', array("fie

我在Woocommerce产品中注册了分类法

在ACF的帮助下,我展示了产品类别下的分类法

因此,在每个产品类别中,我都可以很好地选择分类法并在更新时保存它们

现在,我想在single-product.php和archive-product.php中显示选定的分类法。做不到,。。。几个小时

我通过以下方式在帖子/页面类型上很好地实现了这一点:

<?php $term_list = wp_get_post_terms($post->ID, 'materiali', array("fields" => "all")); ?>
    <?php if( !empty($term_list) ): ?>
      <?php foreach($term_list as $cat) { ?>
        <h3><?php echo $cat->name; ?></h3>
        <div><?php echo $cat->description ?></div>
      <?php } ?>
    </div>
    <?php endif; ?>

。。。但在商业上却不能


现在有人知道怎么做了吗?请?

我认为您的代码是编写的,但在woocommerce中,$post不是全局的,因此请尝试使用$product代替$post

<?php 
 global $product;
$term_list = wp_get_post_terms($product->ID, 'materiali', array("fields" => "all")); ?>
<?php if( !empty($term_list) ): ?>
  <?php foreach($term_list as $cat) { ?>
    <h3><?php echo $cat->name; ?></h3>
    <div><?php echo $cat->description ?></div>
  <?php } ?>
</div>
<?php endif; ?>

希望这对您有所帮助,您可以通过

请确保您获得产品id。谢谢。

我认为您的代码是编写的,但在woocommerce中,$post不是全局的,因此请尝试使用$product代替$post

<?php 
 global $product;
$term_list = wp_get_post_terms($product->ID, 'materiali', array("fields" => "all")); ?>
<?php if( !empty($term_list) ): ?>
  <?php foreach($term_list as $cat) { ?>
    <h3><?php echo $cat->name; ?></h3>
    <div><?php echo $cat->description ?></div>
  <?php } ?>
</div>
<?php endif; ?>

希望这对您有所帮助,您可以通过

确保您获得产品id。谢谢。

wp\u get\u post\u术语仅适用于“post”post类型。改为使用。wp_get_post_术语仅适用于“post”post类型。改用。