0

I currently use that code to display product category on woocommerce single-product pages :

add_action( 'woocommerce_product_meta_end', 'add_cat_single_title', 6 );
function add_cat_single_title() {
    $terms = wp_get_post_terms(get_the_ID(), 'product_cat');
    if (!is_wp_error($terms) && !empty($terms)) { ?>
        <div class="cat-term-title-single" style="display: block;">Cat : <a href="<?php echo esc_url(get_term_link($terms[0])); ?>"><?php echo esc_html($terms[0]->name); ?></a></div>
    <?php }
}

That code displays only 1 category. If the product is from several categories or child categories, they are not displayed.

Some help to display every terms would be appreciated.

1 Answer 1

0

I found in woocommerce meta.php template :

<?php echo wc_get_product_category_list( $product->get_id(), ', ', '<span class="posted_in">' . _n( 'Category:', 'Categories:', count( $product->get_category_ids() ), 'woocommerce' ) . ' ', '</span>' ); ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.