<?php
/**
 * Product Category page.
 * @version   1.1.0
 */
get_header();
?>
<?php
$queried_object = get_queried_object();
$term_queried_slug = $queried_object->slug;
$term_id=$queried_object->term_id;
?>
<section class="category-product">
    <div class="container">
        <div class="row">                

            <?php
            $args_category = array(
                'post_type' => 'product',
                'posts_per_page' => -1,
                'tax_query' => array(
                    array(
                        'taxonomy' => 'product_cat',
                        'field' => 'slug',
                        'terms' => $term_queried_slug,
                    ),
                ),
            );
            $wp_query_cat = new WP_Query($args_category);
            while ($wp_query_cat->have_posts()) : $wp_query_cat->the_post();

                $meta = get_post_meta(get_the_ID());
              // echo $meta['our_agents'][0];
                $agents_found[] = $meta['our_agents'][0];
            endwhile;
            wp_reset_query();



            $agent_ids_filter = array_unique($agents_found);
            // echo $agent_ids = implode(',', $agent_ids_filter);
            $slider_class = 1;
            $counter = 1;
            foreach ($agent_ids_filter as $agent_id) {
                
                $meta = get_post_meta($agent_id);
                $agent_thumb_img = get_field('agent_thumb_img', $agent_id);
                if ($agent_thumb_img) {
                    $agent_thumb_img_url = $agent_thumb_img;
                } else {
                    $agent_thumb_img_url = get_site_url() . '/wp-content/uploads/2018/05/Untitled-1.jpg';
                }
                if ($counter == 1) {
                    ?>
                    <div class="col-md-12 block-one-cat">
                        <div clas="row">
                            <div class="col-md-12 <?php echo $agent_id; ?>" id="banner_image_do_hover<?php echo $slider_class; ?>">
                                <?php 
                               while(the_repeater_field('agent_banner_related_category',$agent_id)):
                                  $banner_agent_cat=get_sub_field('category',$agent_id);
                                 if($banner_agent_cat == $term_id) {                  
                                 $banner_image_url_loop=get_sub_field('big_banner',$agent_id);
                                ?>
                                <a href="javascript:void(0)"><img src="<?php echo $banner_image_url_loop; ?>" class="banner-image-agent"></a>
                                <?php  } 
                                endwhile; ?>
                                <div class="agent-avtar" id="hover_show_div<?php echo $slider_class; ?>" style="display:none;">
                                    <img src="<?php echo $agent_thumb_img_url; ?>" class="agent-thumb-img">
                                </div>
                            </div>
                            <div class="col-md-12">
                                
									<div class="multiple-items">
                                            <?php
                                            
                                            $args = array(
                                                'post_type' => 'product',
                                                'posts_per_page' => -1,
                                                'meta_query' => array(
                                                    array(
                                                        'key' => 'our_agents',
                                                        'value' => $agent_id,
                                                        'compare' => '=',
                                                    )
                                                ),
                                                'tax_query' => array(
                                                    array(
                                                        'taxonomy' => 'product_cat',
                                                        'field' => 'slug',
                                                        'terms' => $term_queried_slug,
                                                    ),
                                                ),
                                            );
                                            $wp_query = new WP_Query($args);
                                            $count_pro=1;
                                            while ($wp_query->have_posts()) : $wp_query->the_post();
                                                $product_image = get_field('category_page_product_image');
                                                $product_default_img_url = get_the_post_thumbnail_url($wp_query->ID, 'full');
                                                if ($product_image) {
                                                    $product_image_url = $product_image;
                                                } elseif ($product_default_img_url) {
                                                    $product_image_url = $product_default_img_url;
                                                } else {
                                                    $product_image_url = get_site_url() . '/wp-content/uploads/2018/05/Untitled-1.jpg';
                                                }
                                                ?>
                                                <div class="item" id="button_hover1<?php echo $count_pro.$slider_class; ?>">
                                                    <a href="<?php the_permalink(); ?>"><img src="<?php echo $product_image_url; ?>"></a>
                                                    <div class="extra-item">

                                                        <div class="wish-list">
                                                            <?php if (( class_exists('YITH_WCWL') && class_exists('YITH_WCWL_Shortcode') ) || etheme_get_option('quick_view')) : ?>

                                                                <?php echo et_wishlist_btn(__('Wishlist', ETHEME_DOMAIN)); ?>
                                                                <?php if (etheme_get_option('quick_view')): ?>
                                                                    <span class="show-quickly" data-prodid="<?php echo $wp_query->ID; ?>"><?php _e('Quick View', ETHEME_DOMAIN) ?></span>
                                                                <?php endif ?>
                                                            <?php endif; ?>
                                                        </div>

                                                        <div class="pro-title">
                                                            <a class="pro-titlee" href="<?php the_permalink(); ?>"><?php the_title(); ?></a>


                                                        </div>

                                                        <div class="wish-price">
                                                            <?php
                                                            /**
                                                             * woocommerce_after_shop_loop_item_title hook
                                                             *
                                                             * @hooked woocommerce_template_loop_rating - 5
                                                             * @hooked woocommerce_template_loop_price - 10
                                                             */
                                                            if (etheme_get_option('product_page_price')) {
                                                                do_action('woocommerce_after_shop_loop_item_title');
                                                            }
                                                            ?>
                                                        </div>
                                                        <div class="clearfix"></div>
                                                       
                                                    </div>
													
													 <div class="footer-btn" id="button_hover_show1<?php echo $count_pro.$slider_class; ?>" style="display:none;"> 
                                                            <center>
                                                                <a href="<?php the_field('page_url'); ?>" class="btn border-grey  product_type_" >SHOP</a>
                                                            </center>
                                                        </div>
                                                    <script>
                                                     jQuery(function () {
                                jQuery('#button_hover1<?php echo $count_pro.$slider_class; ?>').mouseover(function () {

                                    jQuery('#button_hover_show1<?php echo $count_pro.$slider_class; ?>').show();

                                });
                                jQuery('#button_hover1<?php echo $count_pro.$slider_class; ?>').mouseleave(function () {

                                    jQuery('#button_hover_show1<?php echo $count_pro.$slider_class; ?>').hide();

                                });
                                
                            });
													</script>
                                                </div>
                                                
                                                <?php
                                                
                                           $count_pro++; endwhile;
                                            wp_reset_query();
                                            ?>
                                        </div>
								
                            </div>
                        </div>
                    </div>

                    <?php
                } else {
                    ?>
                    <div class="col-md-12 <?php echo $agent_id; ?>">
                        <div class="row">
                            <div class="col-md-6 block-two-cat">
                                
                                <div class="agent-medium" id="banner_image_do_hover<?php echo $slider_class; ?>">
                                     <?php 
                               while(the_repeater_field('agent_banner_related_category',$agent_id)):
                                  $banner_agent_cat_low=get_sub_field('category',$agent_id);
                                 if($banner_agent_cat_low == $term_id) {                  
                                 $banner_image_url_loop_low=get_sub_field('small_banner',$agent_id);
                                ?>
                                <a href="javascript:void(0)"><img src="<?php echo $banner_image_url_loop_low; ?>" class="banner-image-agent-medium"></a> 
                                <?php  } 
                                endwhile; ?>
                                </div>
                                <div class="agent-bottom" id="hover_show_div<?php echo $slider_class; ?>" style="display:none;">
                                    <img src="<?php echo $agent_thumb_img_url; ?>" >
                                </div>
                            </div>
                            <div class="col-md-6 block-two-cat">
                                <div class="single-items">
                                    <?php
                                    $args_else = array(
                                        'post_type' => 'product',
                                        'posts_per_page' => -1,
                                        'meta_query' => array(
                                            array(
                                                'key' => 'our_agents',
                                                'value' => $agent_id,
                                                'compare' => '=',
                                            )
                                        ),
                                        'tax_query' => array(
                                            array(
                                                'taxonomy' => 'product_cat',
                                                'field' => 'slug',
                                                'terms' => $term_queried_slug,
                                            ),
                                        ),
                                    );
                                    $wp_query_else = new WP_Query($args_else);
                                    $count2=1;
                                    while ($wp_query_else->have_posts()) : $wp_query_else->the_post();
                                        $product_image = get_field('category_page_product_image');
                                        $product_default_img_url = get_the_post_thumbnail_url($wp_query_else->ID, 'full');
                                        if ($product_image) {
                                            $product_image_url = $product_image;
                                        } elseif ($product_default_img_url) {
                                            $product_image_url = $product_default_img_url;
                                        } else {
                                            $product_image_url = get_site_url() . '/wp-content/uploads/2018/05/Untitled-1.jpg';
                                        }
                                        ?>
                                        <div class="item" id="button_hover_low<?php echo $slider_class.$count2; ?>">
                                            <div class="inner-div">
                                                <div class="inner-div-contetn">
                                                    <a href="<?php the_permalink(); ?>"><img src="<?php echo $product_image_url; ?>"></a>
                                                    <div class="extra-item-two">
                                                        <div class="wisshh">
														    <?php if (( class_exists('YITH_WCWL') && class_exists('YITH_WCWL_Shortcode') ) || etheme_get_option('quick_view')) : ?>

                                                            <?php echo et_wishlist_btn(__('Wishlist', ETHEME_DOMAIN)); ?>
                                                            <?php if (etheme_get_option('quick_view')): ?>
                                                                <span class="show-quickly" data-prodid="<?php echo $wp_query_else->ID; ?>"><?php _e('Quick View', ETHEME_DOMAIN) ?></span>
                                                            <?php endif ?>
                                                          <?php endif; ?>
														</div>
														<div class="block-two-titlee">
                                                        <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
														</div>
                                                        <div class="block-two-product-price">
                                                            <?php
                                                            /**
                                                             * woocommerce_after_shop_loop_item_title hook
                                                             *
                                                             * @hooked woocommerce_template_loop_rating - 5
                                                             * @hooked woocommerce_template_loop_price - 10
                                                             */
                                                            if (etheme_get_option('product_page_price')) {
                                                                do_action('woocommerce_after_shop_loop_item_title');
                                                            }
                                                            ?>
                                                        </div> 
														<div class="clearfix"></div>
                                                    </div>  
                                                </div>
                                                <div class="footer-btn" id="button_hover_show_low_but<?php echo $slider_class.$count2; ?>" style="display:none;"> 
                                                    <center>
                                                        <a href="<?php the_field('page_url'); ?>"  class="btn border-grey  product_type_" >SHOP</a>
                                                    </center>
                                                </div>
                                            </div>
                                            <script>
                                                     jQuery(function () {
                                jQuery('#button_hover_low<?php echo $slider_class.$count2; ?>').mouseover(function () {

                                    jQuery('#button_hover_show_low_but<?php echo $slider_class.$count2; ?>').show();

                                });
                                jQuery('#button_hover_low<?php echo $slider_class.$count2; ?>').mouseleave(function () {

                                    jQuery('#button_hover_show_low_but<?php echo $slider_class.$count2; ?>').hide();

                                });
                                
                            });
													</script>
                                        </div>
                                        
                                    <?php $count2++; endwhile; ?>

                                </div>
                            </div>
                        
                        <?php
                    }
                    ?> <script type="text/javascript">
                        jQuery(function ()
                        {
                            jQuery(function () {
                                jQuery('#banner_image_do_hover<?php echo $slider_class; ?>').mouseover(function () {

                                    jQuery('#hover_show_div<?php echo $slider_class; ?>').show();

                                });
                                jQuery('#banner_image_do_hover<?php echo $slider_class; ?>').mouseleave(function () {

                                    jQuery('#hover_show_div<?php echo $slider_class; ?>').hide();

                                });
                                
                            });
                        });
                    </script><?php
                    $slider_class++;
                    $counter++;
                    if ($counter == 4) {
                        $counter = 1;
                    }
                }
                ?>
				</div>
            </div>
            </section>

            <script type="text/javascript">
                jQuery(window).load(function () {
                    jQuery('.flexslider').flexslider({
                        animation: "slide"
                    });
                });


                jQuery('.multiple-items').slick({
                    dots: false,
					nav: true,
                    infinite: true,
                    slidesToShow: 4,
                    slidesToScroll: 4,
					autoplay: true,
					autoplaySpeed: 2000
                });

                jQuery('.single-items').slick({
                    dots: false,
					nav: true,
                    infinite: true,
                    slidesToShow: 1,
                    slidesToScroll: 1,
					autoplay: true,
					autoplaySpeed: 2000
                });

            </script>
            <?php get_footer(); ?>
