Skip to content

Instantly share code, notes, and snippets.

@lmartins
Last active November 30, 2015 18:25
Show Gist options
  • Save lmartins/bee80f7ca214fa2fa9ab to your computer and use it in GitHub Desktop.
Save lmartins/bee80f7ca214fa2fa9ab 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