How to get related category/categories in WordPress archive page

I am using WooCommerce in WordPress. I have few categories of products like these,

Example:

Product 1 Category (//parent)
-- Category 1
-- Category 2
-- Category 3
-- Category 4
Product 2 Category (//parent)
-- Category 10
-- Category 11
-- Category 12
-- Category 13

If I am in a archive page for Category 2(sub) How can I get all other category name under the parent category (Product 1 Category) as a list.

what i'm trying

$args = array(
       'hierarchical' = 1,
       'show_option_none' = '',
       'hide_empty' = 0,
       'parent' = $parent_cat_ID,
       'taxonomy' = 'product_cat'
   );
$subcats = get_categories($args);
echo 'ul class="wooc_sclist"';
foreach ($subcats as $sc) {
       $link = get_term_link( $sc-slug, $sc-taxonomy );
echo 'lia href="'. $link .'"'.$sc-name.'/a/li';
     }
echo '/ul';
}

Out put should :

.Category 1
.Category 2
.Category 3
.Category 4

I have use below code which works fine in single-product.php page -

?php 
 $parent = get_category_parents( $cat, true, ' raquo; ' ); 
echo $product-get_categories( ', ', 'span' . _n( 'Category:', 'Categories:', sizeof( get_the_terms( $post-ID, 'product_cat' ) ), 'woocommerce' ) . ' ', './span' ); 
?

Topic woocommerce-offtopic categories archives Wordpress

Category Web


I did this to solve the problem

  <?php 
    $terms = get_the_terms( $post->cat_ID , 'product_cat' );
    foreach ($terms as $term) { 
        $term_id = $term->term_id;
        $term_link = get_term_link( $term, $taxonomy );
        $term_name = $term->name;
        echo '<a class="cat-box" href="' . $term_link . '"><span class="cat-name">' . $term_name . '</span></a>';   
    }
    ?>

I usually do this by getting data from database

$result = mysql_query("SELECT * FROM wp_terms JOIN wp_term_taxonomy
ON wp_term_taxonomy.term_id = wp_terms.term_id 
WHERE wp_term_taxonomy.parent = ".$parent_cat_ID." 
AND wp_term_taxonomy.taxonomy = 'product_cat'");

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.