Add product category tree sidebar to archive and single product pages (v0.1.7)
All checks were successful
Create Release Package / PHP Lint (push) Successful in 1m4s
Create Release Package / PHPUnit Tests (push) Successful in 50s
Create Release Package / Build Release (push) Successful in 58s

Hierarchical category navigation with collapsible sub-levels up to 3 levels
deep, using Bootstrap 5 list-group and collapse components. Sidebar renders
on both archive/shop and single product pages with responsive offcanvas on
mobile. Active category highlighting and ancestor auto-expand for intuitive
navigation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-29 15:19:53 +02:00
parent 5e4af247fa
commit 9860a184cd
9 changed files with 332 additions and 8 deletions

View File

@@ -25,7 +25,9 @@ woocommerce_breadcrumb();
// Fire structured data hook (normally on woocommerce_before_main_content at priority 30).
do_action( 'woocommerce_shop_loop_header' );
$has_sidebar = is_active_sidebar( 'shop-sidebar' );
$has_widgets = is_active_sidebar( 'shop-sidebar' );
$category_tree = wc_bootstrap_get_category_tree();
$has_sidebar = $has_widgets || ! empty( $category_tree );
if ( woocommerce_product_loop() ) {
@@ -62,7 +64,23 @@ if ( woocommerce_product_loop() ) {
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="<?php esc_attr_e( 'Close', 'wc-bootstrap' ); ?>"></button>
</div>
<div class="offcanvas-body p-0">
<?php dynamic_sidebar( 'shop-sidebar' ); ?>
<?php
// Render the category tree.
if ( ! empty( $category_tree ) ) {
$twig = \WPBootstrap\Twig\TwigService::getInstance();
$current_cat = is_product_category() ? get_queried_object_id() : 0;
echo $twig->render( 'global/category-tree.html.twig', [
'categories' => $category_tree,
'shop_url' => wc_get_page_permalink( 'shop' ),
'current_cat' => $current_cat,
] );
}
// Render any configured widgets.
if ( $has_widgets ) {
dynamic_sidebar( 'shop-sidebar' );
}
?>
</div>
</div>
</aside>