WooCommerce: Get the category from an ID of a product?

<?php 
$term_list = wp_get_post_terms($id_product,'product_cat',array('fields'=>'ids'));
$cat_id =(int)$term_list[0];
echo get_term_link ($cat_id,'product_cat');
?>
Advertisements

4 thoughts on “WooCommerce: Get the category from an ID of a product?

  1. Hi Where would I put this code to show the category of the products on the cart page?

    I have added this to the cart.php:

    this adds a new Category column.

    Then later I have this:
    which is where I want the category name to display.

    I have searched everywhere and can’t figure out how I could achieve this.

    Thanks for your help

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s