简体   繁体   中英

Taxonomies of Categories (Woocommerce products)

I have registered taxonomies in Woocommerce products.

With help of ACF i'm showing taxonomies under categories of products.

So, in each product category i can nicely select taxonomies and save them on update.

Now, i would like to show selected taxonomies in single-product.php and archive-product.php. Cannot do it,... for hours.

I manage to nicely do it on post/page type with:

<?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; ?>

... but cannot in woocommerce.

Does anybody now how to do it? Please?

I think your code is write but in the woocommerce $post is not a global ,so instead of $post try to use $product.

<?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; ?>

Hope this will help you, you can try by <?php echo $product->ID; ?> <?php echo $product->ID; ?> To be sure you getting product id.Thanks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM