<?php
/*
* Woocommerce – Work with categories
*/
if ( is_product_category() ){ // Condition for product category
global $wp_query;
$cat = $wp_query->get_queried_object();
$current_cat_id = $cat->term_id;
$cat_parent = $cat->parent; // get category parent
/* Get childrens of category */
$children = get_categories( array (‘taxonomy’ => ‘product_cat’, ‘parent’ => $current_cat_id ));
/*Get category link*/
$cat_link = get_category_link( $current_cat_id );
}
/*Get categories based on product id*/
$terms = get_the_terms( $post->ID, ‘product_cat’ );
foreach ($terms as $term) {
$product_cat = $term->name;
break;
}
?>