0

I'm trying to show product category description on a Woocommerce pdf invoice. Here i'm using this code , but not showing anything.

$cat_id  = $category->term_id;
$term = get_term( $cat_id, 'term', true );
$description = $term->description;

Sample output:

$t.=".$description.";

Any suggestions?

  • As @MarkKaplun suggested, you have to use the correct taxonomy, so product_cat. There is a function term_description() you could use, you might want to take a look at an answer I gave some time ago to pretty much the same topic. – Nicolai Mar 10 '15 at 15:10
  • 1
    Note: In regards to close voting this question, this is about getting the description from a custom taxonomy, so strictly core functionality related, thus IMHO not worthy of closing as not WordPress related. – Nicolai Mar 10 '15 at 15:12
  • See I've successfully got woocommerce category thumbnail using this: $idcat = $ticket_cat['category_id']; $thumbnail_id = get_woocommerce_term_meta( $idcat, 'thumbnail_id', true ); $image = wp_get_attachment_url( $thumbnail_id ); Any suggestion? – Noobie Mar 10 '15 at 16:11
  • @ialocin, i've tried it. nothing happened. It showed blank. – Noobie Mar 14 '15 at 16:19
1

Your code will probably work for post categories, but you need to specify the right taxonomy in the call to get_term to fetch the product category (which is what I assume you want to get). But actually if your $category actually contains the product category then I am not sure you even need to call get_term as the description is probably part of the category object.

  • I've successfully got woocommerce category thumbnail using this: $idcat = $ticket_cat['category_id']; $thumbnail_id = get_woocommerce_term_meta( $idcat, 'thumbnail_id', true ); $image = wp_get_attachment_url( $thumbnail_id ); Any suggestion? – Noobie Mar 10 '15 at 14:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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