-
-
Save joedooley/0780e65c7d5fe8a71e58 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