Last active
November 30, 2015 18:25
-
-
Save lmartins/bee80f7ca214fa2fa9ab to your computer and use it in GitHub Desktop.
Get the top level categories assigned to a product
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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