<?php
/**
 * Custom functions that act independently of the theme templates.
 *
 * Eventually, some of the functionality here could be replaced by core features.
 *
 * @package Pet Bazaar 
 */

/**
 * Adds custom classes to the array of body classes.
 *
 * @param array $classes Classes for the body element.
 * @return array
 */
function pet_bazaar_body_classes( $classes ) {
	// Adds a class of group-blog to blogs with more than 1 published author.
	if ( is_multi_author() ) {
		$classes[] = 'group-blog';
	}

	// Adds a class of hfeed to non-singular pages.
	if ( ! is_singular() ) {
		$classes[] = 'hfeed';
	}
	if ( is_page_template( 'templates/template-homepage.php' ) ) {
		$classes[] = 'home';
	}
	
		//$classes[] = 'pet-bazaar-home2';
	
	return $classes;
}
add_filter( 'body_class', 'pet_bazaar_body_classes' );

if ( ! function_exists( 'wp_body_open' ) ) {
	/**
	 * Backward compatibility for wp_body_open hook.
	 *
	 * @since 1.0.0
	 */
	function wp_body_open() {
		do_action( 'wp_body_open' );
	}
}

if (!function_exists('pet_bazaar_str_replace_assoc')) {

    /**
     * pet_bazaar_str_replace_assoc
     * @param  array $replace
     * @param  array $subject
     * @return array
     */
    function pet_bazaar_str_replace_assoc(array $replace, $subject) {
        return str_replace(array_keys($replace), array_values($replace), $subject);
    }
}

// Comments Counts
if ( ! function_exists( 'pet_bazaar_comment_count' ) ) :
function pet_bazaar_comment_count() {
	$pet_bazaar_comments_count 	= get_comments_number();
	if ( 0 === intval( $pet_bazaar_comments_count ) ) {
		echo esc_html__( '0 Comments', 'pet-bazaar' );
	} else {
		/* translators: %s Comment number */
		 echo sprintf( _n( '%s Comment', '%s Comments', $pet_bazaar_comments_count, 'pet-bazaar' ), number_format_i18n( $pet_bazaar_comments_count ) );
	}
} 
endif;


/**
 * Display Sidebars
 */
if ( ! function_exists( 'pet_bazaar_get_sidebars' ) ) {
	/**
	 * Get Sidebar
	 *
	 * @since 1.0
	 * @param  string $sidebar_id   Sidebar Id.
	 * @return void
	 */
	function pet_bazaar_get_sidebars( $sidebar_id ) {
		if ( is_active_sidebar( $sidebar_id ) ) {
			dynamic_sidebar( $sidebar_id );
		} elseif ( current_user_can( 'edit_theme_options' ) ) {
			?>
			<div class="widget">
				<p class='no-widget-text'>
					<a href='<?php echo esc_url( admin_url( 'widgets.php' ) ); ?>'>
						<?php esc_html_e( 'Add Widget', 'pet-bazaar' ); ?>
					</a>
				</p>
			</div>
			<?php
		}
	}
}

/**
 * Get registered sidebar name by sidebar ID.
 *
 * @since  1.0.0
 * @param  string $sidebar_id Sidebar ID.
 * @return string Sidebar name.
 */
function pet_bazaar_get_sidebar_name_by_id( $sidebar_id = '' ) {

	if ( ! $sidebar_id ) {
		return;
	}

	global $wp_registered_sidebars;
	$sidebar_name = '';

	if ( isset( $wp_registered_sidebars[ $sidebar_id ] ) ) {
		$sidebar_name = $wp_registered_sidebars[ $sidebar_id ]['name'];
	}

	return $sidebar_name;
}


/**
 * Pet Bazaar Logo
 */
if ( ! function_exists( 'pet_bazaar_logo' ) ) {
	function pet_bazaar_logo() {
		if(has_custom_logo())
			{	
				the_custom_logo();
			}
			?>
			<a href="<?php echo esc_url( home_url( '/' ) ); ?>">
				<h4 class="site-title">
					<?php 
						echo esc_html(get_bloginfo('name'));
					?>
				</h4>
			</a>
		<?php
			$pet_bazaar_description = get_bloginfo( 'description');
			if ($pet_bazaar_description) : ?>
				<p class="site-description"><?php echo esc_html($pet_bazaar_description); ?></p>
		<?php endif;
	}
}
add_action( 'pet_bazaar_logo', 'pet_bazaar_logo' );


/**
 * Pet Bazaar Navigation
 */
if ( ! function_exists( 'pet_bazaar_main_nav' ) ) {
	function pet_bazaar_main_nav() {
		wp_nav_menu( 
			array(  
				'theme_location' => 'primary_menu',
				'container'  => '',
				'menu_class' => 'main-menu menu-primary menu-wrap',
				'fallback_cb' => 'WP_Bootstrap_Navwalker::fallback',
				'walker' => new WP_Bootstrap_Navwalker()
				 ) 
			);
	}
}
add_action( 'pet_bazaar_main_nav', 'pet_bazaar_main_nav' );

/**
 * Pet Bazaar Header Cart
 */
if ( ! function_exists( 'pet_bazaar_hdr_cart' ) ) {
	function pet_bazaar_hdr_cart() {
		$pet_bazaar_hs_cart = get_theme_mod( 'hide_show_cart','1');
		if($pet_bazaar_hs_cart=='1' && class_exists( 'woocommerce' )): ?>
			<li class="cart-wrapper">
				<div class="cart-main">
					<button type="button"
						class="cart-icon-wrap header-cart cart-trigger">
						<i class="fa fa-shopping-cart"></i>
						<?php 
							if ( class_exists( 'woocommerce' ) ) {
								$count = WC()->cart->cart_contents_count;
								$cart_url = wc_get_cart_url();
								
								if ( $count > 0 ) {
								?>
									 <span class="cart-count"><?php echo esc_html( $count ); ?></span>
								<?php 
								}
								else {
									?>
									<span class="cart-count"><?php esc_html_e('0','pet-bazaar')?></span>
									<?php 
								}
							}
							?>
					</button>
					<span class="cart-label">
						<span><?php echo WC()->cart->get_cart_subtotal(); ?></span>
					</span>
					<div class="cart-modal cart-modal-1">
						<div class="cart-container">
							<div class="cart-header">
								<div class="cart-top">
									<span class="cart-text"><?php esc_html_e('Shopping Cart','pet-bazaar'); ?></span>
									<a href="javascript:void(0);" class="cart-close"><?php esc_html_e('CLOSE','pet-bazaar'); ?></a>
								</div>
							</div>
							<div class="cart-data">
								<?php get_template_part('woocommerce/cart/mini','cart'); ?>
							</div>	
						</div>
						<div class="cart-overlay"></div>
					</div>
				</div>
			</li>
			<?php endif;
	}
}
add_action( 'pet_bazaar_hdr_cart', 'pet_bazaar_hdr_cart' );


/**
 * Pet_Bazaar Header My Account
 */
if ( ! function_exists( 'pet_bazaar_hdr_account' ) ) {
	function pet_bazaar_hdr_account() {
		$hide_show_account = get_theme_mod( 'hide_show_account','1');
		$hide_show_account_title = get_theme_mod( 'hide_show_account_title','0');
		if($hide_show_account=='1'  && class_exists( 'woocommerce' )): ?>
			<li class="myaccount">
				<?php if(is_user_logged_in()): ?>
					<a href="<?php echo esc_url(wp_logout_url( home_url())); ?>" class="myaccount-btn">
						<i class="fa fa-sign-out"></i>
					</a>
					<?php if($hide_show_account_title=='1'){ ?>
						<p><?php echo esc_html__('Logout','pet-bazaar'); ?></p>
					<?php } ?>
				<?php else: ?>
					<a href="<?php echo get_permalink( get_option('woocommerce_myaccount_page_id') ); ?>" class="myaccount-btn">
						<i class="fa fa-user"></i>
					</a>
					<?php if($hide_show_account_title=='1'){ ?>
						<p><?php echo esc_html__('Login','pet-bazaar'); ?></p>
					<?php } ?>
				<?php endif; ?>
			</li>
		<?php endif;
	}
}
add_action( 'pet_bazaar_hdr_account', 'pet_bazaar_hdr_account' );

/**
 * Pet_Bazaar Browse Category
 */
if ( ! function_exists( 'pet_bazaar_hdr_browse_cat' ) ) {
	function pet_bazaar_hdr_browse_cat() {
		$browse_product_cat			= get_theme_mod('browse_product_cat');
		
		if(class_exists( 'woocommerce' )): 
		?>
			<div class="product-category-menus">
				<div class="product-category-menus-list active">
					<ul class="main-menu">
							<?php
							$taxonomy     = 'product_cat';
							$orderby      = 'name';
							$show_count   = 0;
							$pad_counts   = 0;
							$hierarchical = 1;
							$title        = '';
							$empty        = 0;
							$args = array(
								'taxonomy'     => $taxonomy,
								'orderby'      => $orderby,
								'show_count'   => $show_count,
								'pad_counts'   => $pad_counts,
								'hierarchical' => $hierarchical,
								'title_li'     => $title,
								'hide_empty'   => $empty
							);
							
							$all_categories = get_categories( $args );
							foreach ($all_categories as $cat) {
								$pet_bazaar_product_cat_icon = get_term_meta($cat->term_id, 'pet_bazaar_product_cat_icon', true);
								if($cat->category_parent == 0) {
									$category_id = $cat->term_id;
									$thumbnail_id = get_term_meta( $category_id, 'thumbnail_id', true );
									$image = wp_get_attachment_url( $thumbnail_id );
									$child_class = (pet_bazaar_has_Children($category_id))?'menu-item-has-children':'';
									
									echo '<li class="menu-item main-top-menu '.$child_class.'"><a href="'.get_term_link($cat->slug, 'product_cat').'">'.(!empty($pet_bazaar_product_cat_icon) ? "<i class='fa {$pet_bazaar_product_cat_icon}'></i>":"<img src='{$image}'>"); echo $cat->name.'</a>';
									$args2 = array(
										'taxonomy'     => $taxonomy,
										'parent'       => $category_id,
										'hierarchical' => $hierarchical,
										'hide_empty'   => $empty
									);
									$sub_cats = get_categories( $args2 );
									if($sub_cats) {
										echo '<ul class="dropdown-menu 2-main-top-menu">';
										foreach($sub_cats as $sub_category) {
											$category_id = $sub_category->term_id;
											$thumbnail_id = get_term_meta( $category_id, 'thumbnail_id', true );
											$image = wp_get_attachment_url( $thumbnail_id );
											$child_class = (pet_bazaar_has_Children($sub_category->term_id))?'menu-item-has-children':'';										
									
											$pet_bazaar_product_cat_icon = get_term_meta($sub_category->term_id, 'pet_bazaar_product_cat_icon', true);
											echo  '<li class="menu-item '.$child_class.'"><a class="nav-link" href="'. get_term_link($sub_category->slug, 'product_cat') .'">'.(!empty($pet_bazaar_product_cat_icon) ? "<i class='fa {$pet_bazaar_product_cat_icon}'></i>":"<img src='{$image}'>"); echo $sub_category->name .'</a>';
											
											$args3 = array(
												'taxonomy'     => $taxonomy,
												'parent'       => $sub_category->term_id,
												'hierarchical' => $hierarchical,
												'hide_empty'   => $empty
											);
											$sub_cats3 = get_categories( $args3 );
										
											if($sub_cats3) {
												echo '<ul class="dropdown-menu 3-main-top-menu">';
												foreach($sub_cats3 as $sub_category3) {
													$category_id = $sub_category3->term_id;
													$thumbnail_id = get_term_meta( $category_id, 'thumbnail_id', true );
													$image = wp_get_attachment_url( $thumbnail_id );
													$child_class = (pet_bazaar_has_Children($sub_category3->term_id))?'menu-item-has-children':'';
													
													$pet_bazaar_product_cat_icon = get_term_meta($sub_category3->term_id, 'pet_bazaar_product_cat_icon', true);
													echo  '<li class="menu-item '.$child_class.'"><a class="nav-link" href="'. get_term_link($sub_category3->slug, 'product_cat') .'">'.(!empty($pet_bazaar_product_cat_icon) ? "<i class='fa {$pet_bazaar_product_cat_icon}'></i>":"<img src='{$image}'>"); echo $sub_category3->name .'</a>';
													
													$args4 = array(
														'taxonomy'     => $taxonomy,
														'parent'       => $sub_category3->term_id,
														'hierarchical' => $hierarchical,
														'hide_empty'   => $empty
													);
													$sub_cats4 = get_categories( $args4 );
													if($sub_cats4) {
														echo '<ul class="dropdown-menu 4-main-top-menu">';
														foreach($sub_cats4 as $sub_category4) {
															$category_id = $sub_category4->term_id;
															$thumbnail_id = get_term_meta( $category_id, 'thumbnail_id', true );
															$image = wp_get_attachment_url( $thumbnail_id );
															$child_class = (pet_bazaar_has_Children($sub_category4->term_id))?'menu-item-has-children':'';
															
															$pet_bazaar_product_cat_icon = get_term_meta($sub_category4->term_id, 'pet_bazaar_product_cat_icon', true);
															echo  '<li class="menu-item '.$child_class.'"><a class="nav-link" href="'. get_term_link($sub_category4->slug, 'product_cat') .'">'.(!empty($pet_bazaar_product_cat_icon) ? "<i class='fa {$pet_bazaar_product_cat_icon}'></i>":"<img src='{$image}'>"); echo $sub_category4->name .'</a>';
															
															$args5 = array(
																'taxonomy'     => $taxonomy,
																'parent'       => $sub_category4->term_id,
																'hierarchical' => $hierarchical,
																'hide_empty'   => $empty
															);
															
															$sub_cats5 = get_categories( $args5 );
															if($sub_cats5) {
																echo '<ul class="dropdown-menu 5-main-top-menu">';
																foreach($sub_cats5 as $sub_category5) {
																	$category_id = $sub_category5->term_id;
																	$thumbnail_id = get_term_meta( $category_id, 'thumbnail_id', true );
																	$image = wp_get_attachment_url( $thumbnail_id );
																	$child_class = (pet_bazaar_has_Children($sub_category5->term_id))?'menu-item-has-children':'';
																	
																	$pet_bazaar_product_cat_icon = get_term_meta($sub_category5->term_id, 'pet_bazaar_product_cat_icon', true);
																	echo  '<li class="menu-item '.$child_class.'"><a class="nav-link" href="'. get_term_link($sub_category5->slug, 'product_cat') .'">'.(!empty($pet_bazaar_product_cat_icon) ? "<i class='fa {$pet_bazaar_product_cat_icon}'></i>":"<img src='{$image}'>"); echo $sub_category5->name .'</a>';
																	
																	$args6 = array(
																		'taxonomy'     => $taxonomy,
																		'parent'       => $sub_category5->term_id,
																		'hierarchical' => $hierarchical,
																		'hide_empty'   => $empty
																	);
																	
																	$sub_cats6 = get_categories( $args6 );
																	
																	if($sub_cats6) {
																		echo '<ul class="dropdown-menu 6-main-top-menu">';
																		foreach($sub_cats6 as $sub_category6) {
																			$category_id = $sub_category6->term_id;
																			$thumbnail_id = get_term_meta( $category_id, 'thumbnail_id', true );
																			$image = wp_get_attachment_url( $thumbnail_id );
																			$child_class = (pet_bazaar_has_Children($sub_category6->term_id))?'menu-item-has-children':'';
																			
																			$pet_bazaar_product_cat_icon = get_term_meta($sub_category6->term_id, 'pet_bazaar_product_cat_icon', true);
																			echo  '<li class="menu-item '.$child_class.'"><a class="nav-link" href="'. get_term_link($sub_category6->slug, 'product_cat') .'">'.(!empty($pet_bazaar_product_cat_icon) ? "<i class='fa {$pet_bazaar_product_cat_icon}'></i>":"<img src='{$image}'>"); echo $sub_category6->name .'</a></li>';
																		}
																		echo '</ul>';
																	}
																	echo '</li>';
																}
																echo '</ul>';
															}
															echo '</li>';
														}
														echo '</ul>';
													}
													echo '</li>';
												}
												echo '</ul>';
											}	
											echo '</li>';
											}
											echo '</ul>';
										}
										echo '</li>';
									}
								}
							?>
						</ul>
				</div>
			</div>
		<?php
		endif;
	}
}
add_action( 'pet_bazaar_hdr_browse_cat', 'pet_bazaar_hdr_browse_cat' );

/**
 * Pet_Bazaar Mobile Browse Category
 */
if ( ! function_exists( 'pet_bazaar_hdr_mobile_browse_cat' ) ) {
	function pet_bazaar_hdr_mobile_browse_cat() {
		$pet_bazaar_hs_browse_cat		= get_theme_mod( 'hs_browse_cat','1');
		if($pet_bazaar_hs_browse_cat=='1' && class_exists( 'woocommerce' )):
		?>
			<div class="product-categories d-none">
				<div class="product-categories-list">
					<ul class="main-menu">
						<?php
						$taxonomy     = 'product_cat';
						$orderby      = 'name';
						$show_count   = 0;
						$pad_counts   = 0;
						$hierarchical = 1;
						$title        = '';
						$empty        = 0;
						$args = array(
							'taxonomy'     => $taxonomy,
							'orderby'      => $orderby,
							'show_count'   => $show_count,
							'pad_counts'   => $pad_counts,
							'hierarchical' => $hierarchical,
							'title_li'     => $title,
							'hide_empty'   => $empty
						);
						
						$all_categories = get_categories( $args );
						foreach ($all_categories as $cat) {
							$pet_bazaar_product_cat_icon = get_term_meta($cat->term_id, 'pet_bazaar_product_cat_icon', true);
							if($cat->category_parent == 0) {
								$category_id = $cat->term_id;
								$thumbnail_id = get_term_meta( $category_id, 'thumbnail_id', true );
								$image = wp_get_attachment_url( $thumbnail_id );
								$child_class = (pet_bazaar_has_Children($category_id))?'menu-item-has-children':'';
								
								echo '<li class="menu-item main-top-menu '.$child_class.'"><a href="'.get_term_link($cat->slug, 'product_cat').'">'.(!empty($pet_bazaar_product_cat_icon) ? "<i class='fa {$pet_bazaar_product_cat_icon}'></i>":"<img src='{$image}'>"); echo $cat->name.'</a>'.(!empty($child_class) ? '<span class="mobile-collapsed d-lg-none"><button type="button" class="fa fa-chevron-right" aria-label="'.esc_attr__('Mobile Collapsed','pet-bazaar').'" aria-hidden="true"></button></span>' : '');
								$args2 = array(
									'taxonomy'     => $taxonomy,
									'parent'       => $category_id,
									'hierarchical' => $hierarchical,
									'hide_empty'   => $empty
								);
								$sub_cats = get_categories( $args2 );
								if($sub_cats) {
									echo '<ul class="dropdown-menu 2-main-top-menu">';
									foreach($sub_cats as $sub_category) {
										$category_id = $sub_category->term_id;
										$thumbnail_id = get_term_meta( $category_id, 'thumbnail_id', true );
										$image = wp_get_attachment_url( $thumbnail_id );
										$child_class = (pet_bazaar_has_Children($sub_category->term_id))?'menu-item-has-children':'';
								
										$pet_bazaar_product_cat_icon = get_term_meta($sub_category->term_id, 'pet_bazaar_product_cat_icon', true);
										echo  '<li class="menu-item '.$child_class.'"><a class="dropdown-item" href="'. get_term_link($sub_category->slug, 'product_cat') .'">'.(!empty($pet_bazaar_product_cat_icon) ? "<i class='fa {$pet_bazaar_product_cat_icon}'></i>":"<img src='{$image}'>"); echo $sub_category->name .'</a>'.(!empty($child_class) ? '<span class="mobile-collapsed d-lg-none"><button type="button" class="fa fa-chevron-right" aria-label="'.esc_attr__('Mobile Collapsed','pet-bazaar').'" aria-hidden="true"></button></span>' : '');
										
										$args3 = array(
											'taxonomy'     => $taxonomy,
											'parent'       => $sub_category->term_id,
											'hierarchical' => $hierarchical,
											'hide_empty'   => $empty
										);
										$sub_cats3 = get_categories( $args3 );
									
										if($sub_cats3) {
											echo '<ul class="dropdown-menu 3-main-top-menu">';
											foreach($sub_cats3 as $sub_category3) {
												$category_id = $sub_category3->term_id;
												$thumbnail_id = get_term_meta( $category_id, 'thumbnail_id', true );
												$image = wp_get_attachment_url( $thumbnail_id );
												$child_class = (pet_bazaar_has_Children($sub_category3->term_id))?'menu-item-has-children':'';
												
												$pet_bazaar_product_cat_icon = get_term_meta($sub_category3->term_id, 'pet_bazaar_product_cat_icon', true);
												echo  '<li class="menu-item '.$child_class.'"><a class="dropdown-item" href="'. get_term_link($sub_category3->slug, 'product_cat') .'">'.(!empty($pet_bazaar_product_cat_icon) ? "<i class='fa {$pet_bazaar_product_cat_icon}'></i>":"<img src='{$image}'>"); echo $sub_category3->name .'</a>'.(!empty($child_class) ? '<span class="mobile-collapsed d-lg-none"><button type="button" class="fa fa-chevron-right" aria-label="'.esc_attr__('Mobile Collapsed','pet-bazaar').'" aria-hidden="true"></button></span>' : '');
												
												$args4 = array(
													'taxonomy'     => $taxonomy,
													'parent'       => $sub_category3->term_id,
													'hierarchical' => $hierarchical,
													'hide_empty'   => $empty
												);
												$sub_cats4 = get_categories( $args4 );
												if($sub_cats4) {
													echo '<ul class="dropdown-menu 4-main-top-menu">';
													foreach($sub_cats4 as $sub_category4) {
														$category_id = $sub_category4->term_id;
														$thumbnail_id = get_term_meta( $category_id, 'thumbnail_id', true );
														$image = wp_get_attachment_url( $thumbnail_id );
														$child_class = (pet_bazaar_has_Children($sub_category4->term_id))?'menu-item-has-children':'';
														
														$pet_bazaar_product_cat_icon = get_term_meta($sub_category4->term_id, 'pet_bazaar_product_cat_icon', true);
														echo  '<li class="menu-item '.$child_class.'"><a class="dropdown-item" href="'. get_term_link($sub_category4->slug, 'product_cat') .'">'.(!empty($pet_bazaar_product_cat_icon) ? "<i class='fa {$pet_bazaar_product_cat_icon}'></i>":"<img src='{$image}'>"); echo $sub_category4->name .'</a>'.(!empty($child_class) ? '<span class="mobile-collapsed d-lg-none"><button type="button" class="fa fa-chevron-right" aria-label="'.esc_attr__('Mobile Collapsed','pet-bazaar').'" aria-hidden="true"></button></span>' : '');
														
														$args5 = array(
															'taxonomy'     => $taxonomy,
															'parent'       => $sub_category4->term_id,
															'hierarchical' => $hierarchical,
															'hide_empty'   => $empty
														);
														
														$sub_cats5 = get_categories( $args5 );
														if($sub_cats5) {
															echo '<ul class="dropdown-menu 5-main-top-menu">';
															foreach($sub_cats5 as $sub_category5) {
																$category_id = $sub_category5->term_id;
																$thumbnail_id = get_term_meta( $category_id, 'thumbnail_id', true );
																$image = wp_get_attachment_url( $thumbnail_id );
																$child_class = (pet_bazaar_has_Children($sub_category5->term_id))?'menu-item-has-children':'';
																
																$pet_bazaar_product_cat_icon = get_term_meta($sub_category5->term_id, 'pet_bazaar_product_cat_icon', true);
																echo  '<li class="menu-item '.$child_class.'"><a class="dropdown-item" href="'. get_term_link($sub_category5->slug, 'product_cat') .'">'.(!empty($pet_bazaar_product_cat_icon) ? "<i class='fa {$pet_bazaar_product_cat_icon}'></i>":"<img src='{$image}'>"); echo $sub_category5->name .'</a>'.(!empty($child_class) ? '<span class="mobile-collapsed d-lg-none"><button type="button" class="fa fa-chevron-right" aria-label="'.esc_attr__('Mobile Collapsed','pet-bazaar').'" aria-hidden="true"></button></span>' : '');
																
																$args6 = array(
																	'taxonomy'     => $taxonomy,
																	'parent'       => $sub_category5->term_id,
																	'hierarchical' => $hierarchical,
																	'hide_empty'   => $empty
																);
																
																$sub_cats6 = get_categories( $args6 );
																
																if($sub_cats6) {
																	echo '<ul class="dropdown-menu 6-main-top-menu">';
																	foreach($sub_cats6 as $sub_category6) {
																		$category_id = $sub_category6->term_id;
																		$thumbnail_id = get_term_meta( $category_id, 'thumbnail_id', true );
																		$image = wp_get_attachment_url( $thumbnail_id );
																		$child_class = (pet_bazaar_has_Children($sub_category6->term_id))?'menu-item-has-children':'';
																		
																		$pet_bazaar_product_cat_icon = get_term_meta($sub_category6->term_id, 'pet_bazaar_product_cat_icon', true);
																		echo  '<li class="menu-item '.$child_class.'"><a class="dropdown-item" href="'. get_term_link($sub_category6->slug, 'product_cat') .'">'.(!empty($pet_bazaar_product_cat_icon) ? "<i class='fa {$pet_bazaar_product_cat_icon}'></i>":"<img src='{$image}'>"); echo $sub_category6->name .'</a>'.(!empty($child_class) ? '<span class="mobile-collapsed d-lg-none"><button type="button" class="fa fa-chevron-right" aria-label="'.esc_attr__('Mobile Collapsed','pet-bazaar').'" aria-hidden="true"></button></span>' : '').'</li>';
																	}
																	echo '</ul>';
																}
																echo '</li>';
															}
															echo '</ul>';
														}
														echo '</li>';
													}
													echo '</ul>';
												}
												echo '</li>';
											}
											echo '</ul>';
										}	
										echo '</li>';
										}
										echo '</ul>';
									}
									echo '</li>';
								}
							}
						?>
					</ul>
				</div>
			</div>
		<?php endif;
	}
}
add_action( 'pet_bazaar_hdr_mobile_browse_cat', 'pet_bazaar_hdr_mobile_browse_cat' );


/**
 * Pet Bazaar Product Search
 */
if ( ! function_exists( 'pet_bazaar_hdr_product_search' ) ) {
	function pet_bazaar_hdr_product_search() {
		$pet_bazaar_hs_product_search	= get_theme_mod( 'hs_product_search','1'); 
		 if($pet_bazaar_hs_product_search=='1' && class_exists( 'woocommerce' )): ?>
			<div class="header-search-form">
			<button type="button" class="header-close-menu close-style" aria-label="<?php echo esc_attr__('Header Close Menu','pet-bazaar'); ?>"></button>
			<form name="product-search" method="get" action="<?php echo esc_url(home_url('/')); ?>">
					<input type="search" name="s" class="search header-search-input" name="s" placeholder="<?php echo esc_attr__( 'Search Products', 'pet-bazaar' ); ?>" value="">
					
					<input type="hidden" name="post_type" value="product" />
					<button class="header-search-button" type="submit"><i class="fa fa-search"></i></button>
				</form>
			</div>
		<?php endif;
	}
}
add_action( 'pet_bazaar_hdr_product_search', 'pet_bazaar_hdr_product_search' );


if ( ! function_exists( 'abv_hdr_widget' ) ) {
	function abv_hdr_widget() {
		$pet_bazaar_above_widget = 'pet-bazaar-header-above-widget';
		if ( is_active_sidebar( $pet_bazaar_above_widget ) ){ 
				dynamic_sidebar( 'pet-bazaar-header-above-widget' );
		}elseif ( current_user_can( 'edit_theme_options' ) ) {
			$pet_bazaar_sidebar_name = pet_bazaar_get_sidebar_name_by_id( $pet_bazaar_above_widget );
			?>
			<div class="widget widget_none">
				<p>
					<?php if ( is_customize_preview() ) { ?>
						<a href="JavaScript:void(0);" class="" data-sidebar-id="<?php echo esc_attr( $pet_bazaar_above_widget ); ?>">
					<?php } else { ?>
						<a href="<?php echo esc_url( admin_url( 'widgets.php' ) ); ?>">
					<?php } ?>
						<?php esc_html_e( 'Add widget here.', 'pet-bazaar' ); ?>
					</a>
				</p>
			</div>
			<?php
		}
	}
}
add_action( 'abv_hdr_widget', 'abv_hdr_widget' );

/*
 *
 * Banner Default
 */
 function pet_bazaar_get_banner_default() {
	return apply_filters(
		'pet_bazaar_get_banner_default', wp_json_encode(
				 array(
				array(
					'image_url'       => get_template_directory_uri() . '/assets/images/banner/banner-bg1.png',
					'title'           => esc_html__( 'selected items only', 'pet-bazaar' ),
					'subtitle'         => esc_html__( 'Hot Summer Deals', 'pet-bazaar' ),
					'text2'	  =>  esc_html__( 'Shop Now', 'pet-bazaar' ),
					'link'	  =>  esc_html__( '#', 'pet-bazaar' ),
					'id'              => 'customizer_repeater_banner_001',
				),
				array(
					'image_url'       => get_template_directory_uri() . '/assets/images/banner/banner-bg2.png',
					'title'           => esc_html__( 'selected items only', 'pet-bazaar' ),
					'subtitle'         => esc_html__( 'Spread Your True Love', 'pet-bazaar' ),				
					'text2'	  =>  esc_html__( 'Shop Now', 'pet-bazaar' ),
					'link'	  =>  esc_html__( '#', 'pet-bazaar' ),
					'id'              => 'customizer_repeater_banner_002',
				),
				array(
					'image_url'       => get_template_directory_uri() . '/assets/images/banner/banner-bg3.png',
					'title'           => esc_html__( 'selected items only', 'pet-bazaar' ),
					'subtitle'         => esc_html__( 'New In This Year', 'pet-bazaar' ),				
					'text2'	  =>  esc_html__( 'Shop Now', 'pet-bazaar' ),
					'link'	  =>  esc_html__( '#', 'pet-bazaar' ),
					'id'              => 'customizer_repeater_banner_003',
				)
			)
		)
	);
}

/*
 *
 * Funfact Default
 */
 function pet_bazaar_get_funfact_default() {
	return apply_filters(
		'pet_bazaar_get_funfact_default', wp_json_encode(
				array(
				array(
					'icon_value'       => 'fa-medal',
					'title'           => esc_html__( '100', 'pet-bazaar' ),
					'text'           => esc_html__( 'Pet Awards', 'pet-bazaar' ),
					'id'              => 'customizer_repeater_funfact4_001',
				),
				array(
					'icon_value'       => 'fa-hands-holding',
					'title'           => esc_html__( '200', 'pet-bazaar' ),
					'text'           => esc_html__( 'Pets Adopted', 'pet-bazaar' ),
					'id'              => 'customizer_repeater_funfact4_002',
				),
				array(
					'icon_value'       => 'fa-bath',
					'title'           => esc_html__( '700', 'pet-bazaar' ),
					'text'           => esc_html__( 'Pet Grooming', 'pet-bazaar' ),
					'id'              => 'customizer_repeater_funfact4_003',			
				),
				array(
					'icon_value'       => 'fa-dog',
					'title'           => esc_html__( '50', 'pet-bazaar' ),
					'text'           => esc_html__( 'Professionals', 'pet-bazaar' ),
					'id'              => 'customizer_repeater_funfact4_004',		
				),
				array(
					'icon_value'       => 'fa-house',
					'title'           => esc_html__( '400', 'pet-bazaar' ),
					'text'           => esc_html__( 'Pets Home', 'pet-bazaar' ),
					'id'              => 'customizer_repeater_funfact4_005',		
				),
			)
		)
	);
}


 /**
 * Add WooCommerce Cart Icon With Cart Count (https://isabelcastillo.com/woocommerce-cart-icon-count-theme-header)
 */
function pet_bazaar_add_to_cart_count_fragment( $fragments ) {
	
    ob_start();
    $count = WC()->cart->cart_contents_count; 
    ?> 	
	<?php
    if ( $count > 0 ) {
	?>
		 <span class="cart-count"><?php echo esc_html( $count ); ?></span>
	<?php 
	}
	else {
		?>
		<span class="cart-count"><?php esc_html_e('0','pet-bazaar')?></span>
		<?php 
	}
    ?><?php
 
    $fragments['span.cart-count'] = ob_get_clean();
     
    return $fragments;
}
add_filter( 'woocommerce_add_to_cart_fragments', 'pet_bazaar_add_to_cart_count_fragment' );


function pet_bazaar_add_to_cart_total_fragment( $fragments ) {
	
    ob_start(); 
    ?> 	
	<span class="cart-label">
		<span><?php echo WC()->cart->get_cart_subtotal(); ?></span>
	</span>
   <?php
    $fragments['span.cart-label'] = ob_get_clean();
     
    return $fragments;
}
add_filter( 'woocommerce_add_to_cart_fragments', 'pet_bazaar_add_to_cart_total_fragment' );
 
/**
 * Register widget area.
 *
 * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
 */

function pet_bazaar_widgets_init() {	
	register_sidebar( array(
		'name' => __( 'Header Widget Area', 'pet-bazaar' ),
		'id' => 'pet-bazaar-header-above-widget',
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget' => '</aside>'
	) );
	
	register_sidebar( array(
		'name' => __( 'Sidebar Widget Area', 'pet-bazaar' ),
		'id' => 'pet-bazaar-sidebar-primary',
		'description' => __( 'The Primary Widget Area', 'pet-bazaar' ),
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget' => '</aside>',
		'before_title' => '<h5 class="widget-title"><span></span>',
		'after_title' => '</h5>',
	) );
	
	register_sidebar( array(
		'name' => __( 'Footer Widget Area 1', 'pet-bazaar' ),
		'id' => 'pet-bazaar-footer-widget',
		'description' => __( 'Footer Widget', 'pet-bazaar' ),
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget' => '</aside>',
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	) );
	
	register_sidebar( array(
		'name' => __( 'Footer Widget Area 2', 'pet-bazaar' ),
		'id' => 'pet-bazaar-footer-widget-2',
		'description' => __( 'Footer Widget', 'pet-bazaar' ),
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget' => '</aside>',
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	) );
	
	register_sidebar( array(
		'name' => __( 'Footer Widget Area 3', 'pet-bazaar' ),
		'id' => 'pet-bazaar-footer-widget-3',
		'description' => __( 'Footer Widget', 'pet-bazaar' ),
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget' => '</aside>',
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	) );
	
	register_sidebar( array(
		'name' => __( 'Footer Widget Area 4', 'pet-bazaar' ),
		'id' => 'pet-bazaar-footer-widget-4',
		'description' => __( 'Footer Widget', 'pet-bazaar' ),
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget' => '</aside>',
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	) );
	
	register_sidebar( array(
		'name' => __( 'WooCommerce Widget Area', 'pet-bazaar' ),
		'id' => 'pet-bazaar-woocommerce-sidebar',
		'description' => __( 'This Widget area for WooCommerce Widget', 'pet-bazaar' ),
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget' => '</aside>',
		'before_title' => '<h4 class="widget-title">',
		'after_title' => '</h4>',
	) );
}
add_action( 'widgets_init', 'pet_bazaar_widgets_init' );



/**
 * This Function Check whether Sidebar active or Not
 */
if(!function_exists( 'pet_bazaar_blog_column_layout' )) :
function pet_bazaar_blog_column_layout(){
	if(is_active_sidebar('pet-bazaar-sidebar-primary'))
		{ echo 'col-lg-8'; } 
	else 
		{ echo 'col-lg-12'; }  
} endif;


function pet_bazaar_breadcrumbs() {
	
	$showOnHome	= esc_html__('1','pet-bazaar'); 	// 1 - Show breadcrumbs on the homepage, 0 - don't show
	$delimiter 	= '';   // Delimiter between breadcrumb
	$home 		= esc_html__('Home','pet-bazaar'); 	// Text for the 'Home' link
	$showCurrent= esc_html__('1','pet-bazaar'); // Current post/page title in breadcrumb in use 1, Use 0 for don't show
	$before		= '<li class="active">'; // Tag before the current Breadcrumb
	$after 		= '</li>'; // Tag after the current Breadcrumb
	// $breadcrumb_seprator	= get_theme_mod('breadcrumb_seprator','fa-hand-point-right');
	global $post;
	$homeLink = home_url();

	if (is_home() || is_front_page()) {
 
	if ($showOnHome == 1) echo '<li><a href="' . esc_url($homeLink) . '">  ' . esc_html($home) . '</a></li>';
 
	} else {
 
    echo '<li><a href="' . esc_url($homeLink) . '">  ' . esc_html($home) . '</a> ' . '&nbsp<i class="fa fa-hand-point-right"></i>&nbsp';
 
    if ( is_category() ) 
	{
		$thisCat = get_category(get_query_var('cat'), false);
		if ($thisCat->parent != 0) echo get_category_parents($thisCat->parent, TRUE, ' ' . ' ');
		echo $before . esc_html__('Archive by category','pet-bazaar').' "' . esc_html(single_cat_title('', false)) . '"' .$after;
		
	} 
	
	elseif ( is_search() ) 
	{
		echo $before . esc_html__('Search results for ','pet-bazaar').' "' . esc_html(get_search_query()) . '"' . $after;
	} 
	
	elseif ( is_day() )
	{
		echo '<a href="' . esc_url(get_year_link(get_the_time('Y'))) . '">' . esc_html(get_the_time('Y')) . '</a> ' . '&nbsp<i class="fa fa-hand-point-right"></i>&nbsp';
		echo '<a href="' . esc_url(get_month_link(get_the_time('Y'),get_the_time('m'))) . '">' . esc_html(get_the_time('F')) . '</a> '. '&nbsp<i class="fa fa-hand-point-right"></i>&nbsp';
		echo $before . esc_html(get_the_time('d')) . $after;
	} 
	
	elseif ( is_month() )
	{
		echo '<a href="' . esc_url(get_year_link(get_the_time('Y'))) . '">' . esc_html(get_the_time('Y')) . '</a> ' . esc_attr($delimiter) . '&nbsp<i class="fa fa-hand-point-right"></i>&nbsp';
		echo $before . esc_html(get_the_time('F')) . $after;
	} 
	
	elseif ( is_year() )
	{
		echo $before . esc_html(get_the_time('Y')) . $after;
	} 
	
	elseif ( is_single() && !is_attachment() )
	{
		if ( get_post_type() != 'post' )
		{
			$post_type = get_post_type_object(get_post_type());
			$slug = $post_type->rewrite;
			echo '<a href="' . esc_url($homeLink) . '/' . $slug['slug'] . '/">  ' . $post_type->labels->singular_name . '</a>';
			if ($showCurrent == 1) echo ' ' . esc_attr($delimiter) . '&nbsp<i class="fa fa-hand-point-right"></i>&nbsp' . $before . wp_kses_post(get_the_title()) . $after;
		}
		else
		{
			$cat = get_the_category(); $cat = $cat[0];
			$cats = get_category_parents($cat, TRUE, ' ' . esc_attr($delimiter) . '&nbsp<i class="fa fa-hand-point-right"></i>&nbsp');
			if ($showCurrent == 0) $cats = preg_replace("#^(.+)\s$delimiter\s$#", "$1", $cats);
			echo $cats;
			if ($showCurrent == 1) echo $before . esc_html(get_the_title()) . $after;
		}
 
    }
		
	elseif ( !is_single() && !is_page() && get_post_type() != 'post' && !is_404() ) {
		if ( class_exists( 'WooCommerce' ) ) {
			if ( is_shop() ) {
				$thisshop = woocommerce_page_title();
			}
			if ( is_product_category() ) {
				$term = get_queried_object(); 
				if ( $term && ! is_wp_error( $term ) ) {
					echo $term->name;
				}
			}
		}	
		else  {
			$post_type = get_post_type_object(get_post_type());
			echo $before . $post_type->labels->singular_name . $after;
		}	
	} 
	
	elseif ( !is_single() && !is_page() && get_post_type() != 'post' && !is_404() ) 
	{
		$post_type = get_post_type_object(get_post_type());
		echo $before . $post_type->labels->singular_name . $after;
	} 
	
	elseif ( is_attachment() ) 
	{
		$parent = get_post($post->post_parent);
		$cat = get_the_category($parent->ID); 
		if(!empty($cat)){
		$cat = $cat[0];
		echo get_category_parents($cat, TRUE, ' ' . esc_attr($delimiter) . '&nbsp <i class="fa fa-hand-point-right"></i> &nbsp');
		}
		echo '<a href="' . esc_url(get_permalink($parent)) . '">' . $parent->post_title . '</a>';
		if ($showCurrent == 1) echo ' ' . esc_attr($delimiter) . ' ' . $before . esc_html(get_the_title()) . $after;
 
    } 
	
	elseif ( is_page() && !$post->post_parent ) 
	{
		if ($showCurrent == 1) echo $before . esc_html(get_the_title()) . $after;
	} 
	
	elseif ( is_page() && $post->post_parent ) 
	{
		$parent_id  = $post->post_parent;
		$breadcrumbs = array();
		while ($parent_id) 
		{
			$page = get_page($parent_id);
			$breadcrumbs[] = '<a href="' . esc_url(get_permalink($page->ID)) . '">' . esc_html(get_the_title($page->ID)) . '</a>' . '&nbsp <i class="fa fa-hand-point-right"></i> &nbsp';
			$parent_id  = $page->post_parent;
		}
		
		$breadcrumbs = array_reverse($breadcrumbs);
		for ($i = 0; $i < count($breadcrumbs); $i++) 
		{
			echo $breadcrumbs[$i];
			if ($i != count($breadcrumbs)-1) echo ' ' . esc_attr($delimiter) . '&nbsp <i class="fa fa-hand-point-right"></i> &nbsp';
		}
		if ($showCurrent == 1) echo ' ' . esc_attr($delimiter) . ' ' . $before . esc_html(get_the_title()) . $after;
 
    } 
	elseif ( is_tag() ) 
	{
		echo $before . esc_html__('Posts tagged ','pet-bazaar').' "' . esc_html(single_tag_title('', false)) . '"' . $after;
	} 
	
	elseif ( is_author() ) {
		global $author;
		$userdata = get_userdata($author);
		echo $before . esc_html__('Articles posted by ','pet-bazaar').'' . $userdata->display_name . $after;
	} 
	
	elseif ( is_404() ) {
		echo $before . esc_html__('Error 404 ','pet-bazaar'). $after;
    }
	
    if ( get_query_var('paged') ) {
		if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo '';
		echo ' ( ' . esc_html__('Page','pet-bazaar') . '' . esc_html(get_query_var('paged')). ' )';
		if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo '';
    }
 
    echo '</li>';
 
  }
}