File: /var/www/html/CW-techs/wp-content/themes/cw-techs/header.php
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Security Equipment Depot</title>
<link rel="icon" type="image/x-icon" href="<?php echo get_template_directory_uri(); ?>/img/favicon.ico" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.3/css/bootstrap.min.css"
integrity="sha512-jnSuA4Ss2PkkikSOLtYs8BlYIeeIK1h99ty4YfvRPAlzr377vr3CXDb7sb7eEEBYjDtcYj+AjBH3FLv5uSJuXg=="
crossorigin="anonymous" referrerpolicy="no-referrer" />
<link rel="stylesheet" type="text/css" href="//cdn.jsdelivr.net/npm/slick-carousel@1.8.1/slick/slick.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.9.0/slick-theme.min.css" integrity="sha512-17EgCFERpgZKcm0j0fEq1YCJuyAWdz9KUtv1EjVuaOz8pDnh/0nZxmU6BBXwaaxqoi9PQXnRWqlcDB027hgv9A==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.css" type="text/css" media="all" />
<link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/css/home-session.css">
<link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/css/header.css">
<link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/css/footer.css">
<link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/css/banner.css">
<link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/css/common.css">
<?php wp_head(); ?>
</head>
<body>
<section class="common-header">
<div class="top-section">
<div class="container custom-container">
<div class="top-sec-inner">
<div class="social-icons">
<a href="#" class="ico"><img src="<?php echo get_template_directory_uri(); ?>/img/google.svg" alt="google"></a>
<a href="#" class="ico"><img src="<?php echo get_template_directory_uri(); ?>/img/youtube.svg" alt="youtube"></a>
<a href="#" class="ico"><img src="<?php echo get_template_directory_uri(); ?>/img/insta.svg" alt="insta"></a>
<a href="#" class="ico"><img src="<?php echo get_template_directory_uri(); ?>/img/Linkedin.svg" alt="Linkedin"></a>
<!-- <a href="#" class="ico"><img src="<?php echo get_template_directory_uri(); ?>/img/Linkedin.svg" alt="Linkedin"></a> -->
<a href="#" class="ico"><img src="<?php echo get_template_directory_uri(); ?>/img/Twitter.svg" alt="Twitter"></a>
</div>
<!-- <div class="search-bar">
<input type="text" class="form-control search-input" placeholder="Search">
<button class="search-btn">
<img src="<?php echo get_template_directory_uri(); ?>/img/search.svg" alt="search">
</button>
</div> -->
<!-- <div class="search-bar">
<input type="text" class="form-control search-input product-search" placeholder="Search">
<div class="suggestions-box product-suggestions"></div>
<button class="search-btn">
<img src="<?php echo get_template_directory_uri(); ?>/img/search.svg" alt="search">
</button>
</div> -->
<form class="search-bar" method="get" action="<?php echo esc_url( home_url('/') ); ?>">
<div >
<input type="text" name="s" class="form-control search-input product-search" placeholder="Search" autocomplete="off" />
<div class="suggestions-box product-suggestions"></div>
<button type="submit" class="search-btn">
<img src="<?php echo get_template_directory_uri(); ?>/img/search.svg" alt="search" />
</button>
<input type="hidden" name="post_type" value="product" />
</div>
</form>
<div class="contact-info">
<span>Contact Us: <a href="tel: +00 0000 0000 00" class="nmbr"> +00 0000 0000 00</a></span>
</div>
</div>
</div>
</div>
<header class="header">
<nav class="navbar navbar-expand-lg">
<div class="container-fluid">
<div class="header-inner">
<div class="logo-sec">
<a class="logo" href="<?=site_url();?>"><img src="<?php echo get_template_directory_uri(); ?>/img/logo.svg" alt="logo"></a>
<div class="outer-sec">
<button class="search-btn serach-btn-mob">
<img src="<?php echo get_template_directory_uri(); ?>/img/search.svg" alt="search">
</button>
<a class="cart-mob" href="<?php echo wc_get_cart_url(); ?>">
<span class="icons">
<img src="<?php echo get_template_directory_uri(); ?>/img/cart.svg" alt="cart">
<span class="badge"><?php echo WC()->cart->get_cart_contents_count(); ?></span>
</span>
</a>
<button class="navbar-toggler custom-toggler" type="button">
<span class="bar"></span>
<span class="bar"></span>
<span class="bar"></span>
</button>
</div>
<div class="search-bar search-bar-mob d-none">
<input type="text" class="form-control search-input product-search" placeholder="Search">
<div class="suggestions-box product-suggestions"></div>
</div>
</div>
<div class="collapse navbar-collapse nav-bar-inner" id="navbarNav">
<ul class="navbar-nav">
<?php
$args = [
'taxonomy' => 'product_cat',
'orderby' => 'name',
'hide_empty' => false,
'parent' => 0,
];
$categories = get_terms($args);
// Get current queried object
$current_term = get_queried_object();
foreach ($categories as $category) :
$children = get_terms([
'taxonomy' => 'product_cat',
'parent' => $category->term_id,
'hide_empty' => false,
]);
// Check if this is the current category
$is_active_parent = ( isset($current_term->term_id) && $current_term->term_id == $category->term_id );
// Also check if any child is active
$is_active_child = false;
foreach ($children as $child) {
if ( isset($current_term->term_id) && $current_term->term_id == $child->term_id ) {
$is_active_child = true;
break;
}
}
$active_class = ($is_active_parent || $is_active_child) ? 'active' : '';
?>
<li class="nav-item dropdown <?php echo $active_class; ?>">
<a class="nav-link dropdown-toggle <?php echo $active_class; ?>" href="<?php echo esc_url(get_term_link($category)); ?>" data-bs-toggle="dropdown">
<?php echo esc_html($category->name); ?>
</a>
<?php if (!empty($children)) : ?>
<ul class="dropdown-menu">
<?php foreach ($children as $child) :
$child_active = ( isset($current_term->term_id) && $current_term->term_id == $child->term_id ) ? 'active' : '';
?>
<li>
<a class="dropdown-item <?php echo $child_active; ?>" href="<?php echo esc_url(get_term_link($child)); ?>">
<?php echo esc_html($child->name); ?>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
<!-- Notification Section -->
<div class="notification-sec">
<?php if ( is_user_logged_in() ) :
$user_id = get_current_user_id();
$favorites = get_user_meta($user_id, 'favorite_products', true);
$favorites = is_array($favorites) ? $favorites : [];
$favorites_count = count($favorites);
?>
<a href="<?= site_url('favorites') ?>" class="icon-btn <?php echo is_page('favorites') ? 'active' : ''; ?>">
<span class="icons">
<img src="<?php echo get_template_directory_uri(); ?>/img/Heart.svg" alt="favorite">
<span class="badge"><?= $favorites_count ?></span>
</span>
Favorites
</a>
<?php endif; ?>
<a href="<?php echo wc_get_cart_url(); ?>" class="icon-btn <?php if (is_cart()) echo 'active'; ?> cart-desk">
<span class="icons">
<img src="<?php echo get_template_directory_uri(); ?>/img/cart.svg" alt="cart">
<span class="badge"><?php echo WC()->cart->get_cart_contents_count(); ?></span>
</span>
Cart
</a>
<a class="icon-btn <?php echo is_page('contact-us') ? 'active' : ''; ?>" href="<?= site_url('contact-us') ?>">Contact Us</a>
<?php
if ( ! is_user_logged_in() ) {
// Redirect to custom login page
$redirect_url = home_url( '/login' );
$user_name = 'Login/Register';
} else {
// Redirect to My Account page
$redirect_url = get_permalink( get_option( 'woocommerce_myaccount_page_id' ) );
$current_user = wp_get_current_user();
$user_name = $current_user->first_name;
}
// Check if current URL matches redirect URL
$current_url = home_url( add_query_arg( [], $_SERVER['REQUEST_URI'] ) );
$is_active = trailingslashit( $current_url ) === trailingslashit( $redirect_url ) ? 'active' : '';
?>
<a href="<?php echo esc_url( $redirect_url ); ?>" class="icon-btn login-btn <?php echo esc_attr( $is_active ); ?>">
<span class="icons">
<img src="<?php echo get_template_directory_uri(); ?>/img/login-ico.svg" alt="login">
</span>
<span><?php echo esc_html( $user_name ); ?></span>
</a>
</div>
</div>
</div>
</div>
</nav>
</header>
</section>