<?php
/**
 * The template for displaying product category thumbnails within loops
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/content-product_cat.php.
 *
 * HOWEVER, on occasion WooCommerce will need to update template files and you (the theme developer).
 * will need to copy the new files to your theme to maintain compatibility. We try to do this.
 * as little as possible, but it does happen. When this occurs the version of the template file will.
 * be bumped and the readme will list any important changes.
 *
 * @see 	    http://docs.woothemes.com/document/template-structure/
 * @author 		WooThemes
 * @package 	WooCommerce/Templates
 * @version     2.5.0
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

global $woocommerce_loop;

// Store loop count we're currently on
if ( empty( $woocommerce_loop['loop'] ) ) {
	$woocommerce_loop['loop'] = 0;
}

// Store column count for displaying the grid
if ( empty( $woocommerce_loop['columns'] ) ) {
	$woocommerce_loop['columns'] = apply_filters( 'loop_shop_columns', 4 );
}

// Increase loop count
$woocommerce_loop['loop'] ++;

// Extra post classes
$classes = array();

if ( ! ( isset( $woocommerce_loop['layout'] ) && ! empty( $woocommerce_loop['layout'] ) ) ) {
    $woocommerce_loop['layout'] = yit_get_option( 'shop-layout', 'with-hover' );
}

// view
if ( ! ( isset( $woocommerce_loop['view'] ) && ! empty( $woocommerce_loop['view'] ) ) ) {
    $woocommerce_loop['view'] = yit_get_option( 'shop-view', 'grid' );
}

$classes[] = $woocommerce_loop['view'];

if ( 0 == ( $woocommerce_loop['loop'] - 1 ) % $woocommerce_loop['columns'] || 1 == $woocommerce_loop['columns'] ) {
    $classes[] = 'first';
}
if ( 0 == $woocommerce_loop['loop'] % $woocommerce_loop['columns'] ) {
    $classes[] = 'last';
}

$classes[] = 'product-category';

// control for the product counter
if ( ! isset( $show_counter ) || ! $show_counter ) {
    $show_counter = yit_get_option( 'shop-category-count' );
}
// control for the discovery text
if ( ! isset( $discovery_text ) || ! $discovery_text ) {
    $discovery_text = yit_get_option( 'discovery-text' );
}
// control for the category's style
if ( ! isset( $style ) || ! $style ) {
    $style = yit_get_option( 'shop-category-style' );
}
// Put the style in the <li> tag
if ( $style == 'white' ): $classes[] = 'white';
else: $classes[] = 'black'; endif;

yit_detect_span_catalog_image( $classes ); //automatically add the classes
?>
<li <?php post_class( wc_product_cat_class( $classes ) ); ?>>

    <?php do_action( 'woocommerce_before_subcategory', $category ); ?>

    <?php

    // Took the thumbnail infos from woocommerce
    $small_thumbnail_size = apply_filters( 'single_product_small_thumbnail_size', 'shop_catalog' );
    $thumbnail_id = get_woocommerce_term_meta( $category->term_id, 'thumbnail_id', true );

    // Put this infos in yit_image
    $default_cat_img = wc_placeholder_img_src();
    $values_category = yit_image( "id={$thumbnail_id}&output=array&size={$small_thumbnail_size}&default={$default_cat_img} " );
    ?>

    <a href="<?php echo get_term_link( $category->slug, 'product_cat' ); ?>" style="background:url('<?php yit_image( "id={$thumbnail_id}&output=url" ); ?>'); height:<?php echo $values_category[2] - 14; ?>px ;">

        <div class="show-category-background">

            <?php
            /**
             * woocommerce_before_subcategory_title hook
             *
             * @hooked woocommerce_subcategory_thumbnail - 10
             */
            do_action( 'woocommerce_before_subcategory_title', $category );

            /**
             * woocommerce_shop_loop_subcategory_title hook.
             *
             * @hooked woocommerce_template_loop_category_title - 10
             */
            do_action( 'woocommerce_shop_loop_subcategory_title', $category , $show_counter , $discovery_text);

            /**
             * woocommerce_after_subcategory_title hook
             */
            do_action( 'woocommerce_after_subcategory_title', $category );
            ?>
        </div>

    </a>
    <?php do_action( 'woocommerce_after_subcategory', $category ); ?>
</li>
