I am new in wordpress and I am using RT-Theme 17. I am developing e-commerce site and I want product category name when I go to the specifically a product detail. how to show the product category name there.
I also used this source code but I did not get category id(term_id)
$cate = get_queried_object();
$cateID = $cate->term_id;
echo $cateID;
I found the result is:-
WP_Post Object
(
[ID] => 1140
[post_author] => 1
[post_date] => 2016-07-27 13:42:38
[post_date_gmt] => 2016-07-27 13:42:38
[post_content] => Energizer professional series heavy duty jumper cables for all vehicle types plus full size trucks, vans and SUVs. Red/black PVC-coated insulated clamps for easy identification. Tangle-free cables remains flexible even at -40°C. Heavy duty copper. 1 Gauge, 30 Ft, 800 AMP. All weather use.
[post_title] => ENB130
[post_excerpt] =>
[post_status] => publish
[comment_status] => closed
[ping_status] => closed
[post_password] =>
[post_name] => enb130
[to_ping] =>
[pinged] =>
[post_modified] => 2016-08-03 19:05:34
[post_modified_gmt] => 2016-08-03 19:05:34
[post_content_filtered] =>
[post_parent] => 0
[guid] => http://energizerpower.com/?post_type=products&p=1140
[menu_order] => 0
[post_type] => products
[post_mime_type] =>
[comment_count] => 0
[filter] => raw
)
You can try below code. It display all categories (separate by comma) assigned to that product .
<?php global $post, $product;
$cat_count = sizeof( get_the_terms( $post->ID, 'product_cat' ) ); ?>
<?php echo $product->get_categories( ', ', '<span class="posted_in">' . _n( 'Category:', 'Categories:', $cat_count, 'woocommerce' ) . ' ', '</span>' ); ?>