Get main parent categories for a product
just to offer a alternative solution that might help somebody: code function wc_origin_trail_ancestor( $link = false, $trail = false ) { if (is_product_category()) { global $wp_query; $q_obj = $wp_query->get_queried_object(); $cat_id = $q_obj->term_id; $descendant = get_term_by(“id”, $cat_id, “product_cat”); $descendant_id = $descendant->term_id; $ancestors = get_ancestors($cat_id, ‘product_cat’); $ancestors = array_reverse($ancestors); $origin_ancestor = get_term_by(“id”, $ancestors[0], “product_cat”); $origin_ancestor_id = $origin_ancestor->term_id; … Read more