I need a woocommerce expert that can help me to get the Most top level category of a category assigned to a product.
Already tried with the following code but it brakes the page
global $post;
$terms = get_the_terms( $post->ID, 'product_cat' );
foreach ($terms as $term) {
$product_cat_id = $term->term_id;
$thetop_parent = woocommerce_get_term_top_most_parent( $product_cat_id , 'product_cat' );
echo $thetop_parent;
}