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 '<li><a 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, ' » ' );
echo $product->get_categories( ', ', '<span>' . _n( 'Category:', 'Categories:', sizeof( get_the_terms( $post->ID, 'product_cat' ) ), 'woocommerce' ) . ' ', '.</span>' );
?>
get_terms
. Woocommerce uses custom taxonomies, and not the build in taxonomycategory