Created
November 30, 2021 05:02
-
-
Save ejcabquina/066da209083cc5d585ff48979786419c to your computer and use it in GitHub Desktop.
Niche display subcategory only.
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
<?php | |
$cat_args = array( | |
'orderby' => 'name', | |
'order' => 'asc', | |
'hide_empty' => true, | |
); | |
$product_categories = get_terms( 'product_cat', $cat_args ); | |
if ( ! empty( $product_categories ) && is_shop() ) { | |
echo '<ul class="woo-cat-nav">'; | |
foreach ( $product_categories as $key => $category ) { | |
printf( | |
'<li> | |
<a href="%1$s"> | |
%2$s | |
</a> | |
</li>', | |
get_term_link( $category ), | |
$category->name | |
); | |
} | |
echo '</ul>'; | |
} | |
if ( is_product_category() ) { | |
$parent_id = get_queried_object_id(); | |
$args = array( | |
'parent' => $parent_id, | |
'orderby' => 'name', | |
'order' => 'asc', | |
'hide_empty' => true, | |
); | |
$terms = get_terms( 'product_cat', $args ); | |
if(! empty( $terms ) ){ | |
echo '<ul class="woo-cat-nav">'; | |
foreach ( $terms as $key => $category ) { | |
printf( | |
'<li> | |
<a href="%1$s"> | |
%2$s | |
</a> | |
</li>', | |
get_term_link( $category ), | |
$category->name | |
); | |
} echo '</ul>'; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment