admin管理员组文章数量:1130349
When a user clicks on a product category from the WooCommerce shop page, instead of the default, I need it to look like the below design, the second picture marks what I mean:
So basically, I need to iterate through each subcategory, display it, check it it has subcategories, and, if it does, display them. I'm currently able to get the sub-subcategory level using the answer from this post and hooking it to "woocommerce_after_subcategory":
I just need help checking to see if those subcategories have a subcategory and then displaying them.
Please let me know if I need to further explain something! Thanks!
When a user clicks on a product category from the WooCommerce shop page, instead of the default, I need it to look like the below design, the second picture marks what I mean:
So basically, I need to iterate through each subcategory, display it, check it it has subcategories, and, if it does, display them. I'm currently able to get the sub-subcategory level using the answer from this post and hooking it to "woocommerce_after_subcategory":
https://wordpress.stackexchange/a/101273
I just need help checking to see if those subcategories have a subcategory and then displaying them.
Please let me know if I need to further explain something! Thanks!
Share Improve this question edited Apr 13, 2017 at 12:37 CommunityBot 1 asked Jan 26, 2016 at 19:16 asdfasdf 211 silver badge4 bronze badges1 Answer
Reset to default 1I solved this by modifying the function linked to in the question to make it recursive. The comments explain my changes:
function woocommerce_subcats_from_parentcat_by_ID( $parent_cat_ID ) {
$args = array(
'hierarchical' => 1,
'show_option_none' => '',
'hide_empty' => 0,
'parent' => $parent_cat_ID,
'taxonomy' => 'product_cat'
);
$subcats = get_categories($args);
if ( $subcats ) { // added if statement to check if there are subcategories
echo '<ul class="product-category-list">';
foreach ($subcats as $sc) {
$link = get_term_link( $sc->slug, $sc->taxonomy );
echo '<li><a href="'. $link .'">'.$sc->name.'</a></li>';
woocommerce_subcats_from_parentcat_by_ID( $sc->term_id ); // function calls itself
}
echo '</ul>';
} else {
return; //return if no subcategories
}} // last bracket kept being pushed out of code block if I used a line break
I'm sure there is a more efficient way to do this instead of having the function call itself every time but this works.
When a user clicks on a product category from the WooCommerce shop page, instead of the default, I need it to look like the below design, the second picture marks what I mean:
So basically, I need to iterate through each subcategory, display it, check it it has subcategories, and, if it does, display them. I'm currently able to get the sub-subcategory level using the answer from this post and hooking it to "woocommerce_after_subcategory":
I just need help checking to see if those subcategories have a subcategory and then displaying them.
Please let me know if I need to further explain something! Thanks!
When a user clicks on a product category from the WooCommerce shop page, instead of the default, I need it to look like the below design, the second picture marks what I mean:
So basically, I need to iterate through each subcategory, display it, check it it has subcategories, and, if it does, display them. I'm currently able to get the sub-subcategory level using the answer from this post and hooking it to "woocommerce_after_subcategory":
https://wordpress.stackexchange/a/101273
I just need help checking to see if those subcategories have a subcategory and then displaying them.
Please let me know if I need to further explain something! Thanks!
Share Improve this question edited Apr 13, 2017 at 12:37 CommunityBot 1 asked Jan 26, 2016 at 19:16 asdfasdf 211 silver badge4 bronze badges1 Answer
Reset to default 1I solved this by modifying the function linked to in the question to make it recursive. The comments explain my changes:
function woocommerce_subcats_from_parentcat_by_ID( $parent_cat_ID ) {
$args = array(
'hierarchical' => 1,
'show_option_none' => '',
'hide_empty' => 0,
'parent' => $parent_cat_ID,
'taxonomy' => 'product_cat'
);
$subcats = get_categories($args);
if ( $subcats ) { // added if statement to check if there are subcategories
echo '<ul class="product-category-list">';
foreach ($subcats as $sc) {
$link = get_term_link( $sc->slug, $sc->taxonomy );
echo '<li><a href="'. $link .'">'.$sc->name.'</a></li>';
woocommerce_subcats_from_parentcat_by_ID( $sc->term_id ); // function calls itself
}
echo '</ul>';
} else {
return; //return if no subcategories
}} // last bracket kept being pushed out of code block if I used a line break
I'm sure there is a more efficient way to do this instead of having the function call itself every time but this works.
本文标签: WooCommerceDisplay nested list of all subcategories on archiveproductphp
版权声明:本文标题:WooCommerce - Display nested list of all subcategories on archive-product.php 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749198111a2331334.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论