Monday, 8 June 2015

How to get category name from the product id in woocommerce

How to get category name from the product id in woocommerce.


// Get the product id from the order id -

<?php
$order = new WC_Order( $order->id );

$items = $order->get_items();

foreach ( $items as $itemty ) {
    $product_id = $itemty['product_id'];
}

// then from product id get the category name

$cat_id=get_the_terms( $product_id, 'product_cat' );

foreach ( $cat_id as $ite ) { 
echo  $cat = $ite->name."<br>";
}

?>


Share:

0 comments:

Post a Comment

Blogger Tutorials

Blogger Templates

d-koder - Web Developer / Security Specialist / Penetration Tester I would like to write tutorials about the issue we use to get while coding something. Hope these small tuts will help developers worldwide. > Website

Interested In -

Html/Css
PHP
Javascript
Jquery
Ajax
JSON
GITHUB