HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux wordpress-ubuntu-s-2vcpu-4gb-fra1-01 5.4.0-169-generic #187-Ubuntu SMP Thu Nov 23 14:52:28 UTC 2023 x86_64
User: root (0)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/dinamo-shop/wp-content/themes/dinamo-shop/woocommerce/global/sidebar.php
<?php
/**
* Sidebar
*/

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
}



// get all product categories
$categories = get_categories(array(
	'taxonomy' => 'product_cat',
));

?>




<?php if( $categories ) : ?>

	<div class="col-auto hide-md">

		<div class="filter-sidebar">
			<h3><?php _e('Kategorije', 'dinamo_shop'); ?></h3>
			<div class="accordion">

				<?php
				$current_term_id = get_queried_object()->term_id;
				$current_term = get_term($current_term_id);
				foreach( $categories as $cat ) : ?>
				<?php
				// don't display "Uncategorized" category
				if( $cat->name == 'Uncategorized' ) {
					continue;
				}


				?>


				<?php
				// display only top level categories
				if( $cat->category_parent == 0 ) { ?>

					<?php
					// get sub categories for current top level category
					$sub_categories = get_categories(array(
						'taxonomy' => 'product_cat',
						'parent'   => $cat->term_id,
					));

					$cats1array = array_column( $sub_categories, 'term_id');

					$cats2array = [];
					foreach( $sub_categories as $subcat ){
						$sub_categories2 = get_categories(array(
							'taxonomy' => 'product_cat',
							'parent'   => $subcat->term_id,
						));
						$cats2array = array_merge( $cats2array, array_column( $sub_categories2, 'term_id' ));
					}

					$cats_array = array_merge( $cats1array, $cats2array );

					?>

					<?php if( in_array( $current_term_id, $cats_array ) || $current_term_id == $cat->term_id || $current_term->parent == $cat->term_id ){
						$active = true;
					} else {
						$active = false;
					}
					?>

					<div class="accordion-item <?php echo ($active) ? "active" : ""; ?>">
						<a data-product-ajax-link href="<?php echo get_term_link( $cat->term_id, 'product_cat' ); ?>" class="accordion-header" data-product-category="<?php echo $cat->term_id; ?>">
							<?php echo $cat->name; ?>
							<?php if( $sub_categories ) : ?>
								<svg class="icon-arrow"><use xlink:href="<?php echo THEMEROOT; ?>/assets/icons/icons.svg#icon-arrow"></use></svg>
							<?php endif; ?>
						</a>


						<?php if( $sub_categories ) { ?>
							<div class="accordion-panel" <?php echo ($active) ? "style='display:block'" : ""; ?>>
								<ul class="accordion-panel-list">
									<?php foreach( $sub_categories as $subcat ) : ?>

										<?php
										// get sub categories for current sub level category
										$sub_categories2 = get_categories(array(
											'taxonomy' => 'product_cat',
											'parent'   => $subcat->term_id,
										));

										if( $sub_categories2 ){
											$ajax = "";
											$cat  = "";
										} else {
											$ajax = "data-product-ajax-link";
											$cat  = "data-product-category='$subcat->term_id'";
										}

										 if( in_array( $current_term_id, array_column( $sub_categories2, 'term_id') ) || $current_term_id == $subcat->term_id || $current_term->parent == $subcat->term_id ) {
											$active = true;
										} else {
											$active = false;
										}

										?>

										<li>
											<div class="accordion-panel-item accordion-item <?php echo ($active) ? "active" : ""; ?>">
												<a data-product-ajax-link href="<?php echo get_term_link( $subcat->term_id, 'product_cat' ); ?>" <?php echo $ajax; ?> <?php echo $cat; ?>  class="accordion-header">
													<?php echo $subcat->name; ?>
													<?php if( $sub_categories2 ) : ?>
														<svg class="icon-arrow"><use xlink:href="<?php echo THEMEROOT; ?>/assets/icons/icons.svg#icon-arrow"></use></svg>
													<?php endif; ?>
												</a>

												<?php if( $sub_categories2 ) : ?>
												<div class="accordion-panel" <?php echo ($active) ? "style='display:block'" : ""; ?>>
													<ul class="accordion-panel-list">
														<?php foreach( $sub_categories2 as $subcat2 ) : ?>
														<li><a data-product-ajax-link href="<?php echo get_term_link( $subcat2->term_id, 'product_cat' ); ?>" class="accordion-panel-item <?= ($current_term_id == $subcat2->term_id || $current_term->parent == $subcat2->term_id) ? "active" : "" ?>" data-product-category="<?php echo $subcat2->term_id; ?>"> <?php echo $subcat2->name; ?></a></li>
														<?php endforeach; ?>
													</ul>
												</div>
											<?php endif; ?>
										</div>
									</li>

										<?php endforeach; ?>
									</ul>
								</div>
							<?php } ?>
						</div>
					<?php } ?>
				<?php endforeach; ?>


				<?php 
				$sale_products = new WP_Query( array(
					'post_type'      => 'product',
					'posts_per_page' => -1,
					'meta_query'     => array(
					array(
						'key'     => 'is_sale',
						'value'   => 1,
						'compare' => '='
					)
					)
				));
				?>

				<?php if( get_field( 'display_sale_page', 'option' ) && $sale_products->have_posts() ) : ?>

				<?php $sale_page = get_field( 'sale_products_page', 'option' ); ?>

				<div class="accordion-item <?php echo ($active) ? "active" : ""; ?>">
					<a data-product-ajax-link href="<?php echo get_permalink($sale_page); ?>" class="accordion-header">
						Sale
					</a>
				</div>

				<?php endif; ?>



			</div>
		</div>
	</div>
<?php endif; ?>