Skip to content

Instantly share code, notes, and snippets.

@joedooley
Forked from lmartins/woo.php
Created November 30, 2015 18:25
Show Gist options
  • Save joedooley/0780e65c7d5fe8a71e58 to your computer and use it in GitHub Desktop.
Save joedooley/0780e65c7d5fe8a71e58 to your computer and use it in GitHub Desktop.
Get the top level categories assigned to a product
function mw_theme_categories( $context )
{
$args = array( 'taxonomy' => 'product_cat' );
$terms = wp_get_post_terms( $context['post']->ID ,'product_cat', $args );
foreach ($terms as $cat) {
if($cat->parent == 0){
$out = '<div class="prodLabel prodLabel--' . strtolower( $cat->name ) . '">';
$out .= "<a href='/product-category/$cat->slug'>$cat->name</a>";
$out .= '</div>';
echo $out;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment