<?php 
/**
* Home page - Tabbed product section
*/
if ( !function_exists( 'store_expert_home_tab_product_block' ) ) {
    // Function
    function store_expert_home_tab_product_block() {

    // Check if the section is enabled in customizer
    if ( get_theme_mod( 'store_expert_products_by_category_enable', 1 ) == 1 ) : 

    // Check if WooCommerce plugin is activated
    if ( store_expert_is_woocommerce_activated() ) : ?>
    <section id="tab-products" class=" home-section">
        <div class="tab-wrapper container">
                <div class="tabber-content">            
            <div class="tab-headers"> 
                <div class="container">
                    <div class="row tab-products">
                        <div class="tab-header-title col-sm">
                            <h3><?php echo esc_html( get_theme_mod( 'store_expert_products_by_category_title', __( 'Product by Category', 'store-expert' ))); ?></h3>
                            <p><?php echo esc_html( get_theme_mod( 'store_expert_products_by_category_subtitle', __( 'Use this place to display products based on category', 'store-expert' ))); ?></p>
                        </div><!-- .tab-header-title -->
                        <div class="tab-nav col-md-auto">
                            <ul>
                                <?php 
                                $counter1 = 0;
                                $counter2 = 0;
                                $cats_id = get_theme_mod( 'store_expert_select_product_categories' );
                                $cats_ids = explode (",", $cats_id);
                                foreach( $cats_ids as $cats_name ) : 
                                    $term = get_term_by( 'slug', $cats_name, 'product_cat' ); 
                                    ?>
                                    <li><a href="#tab<?php echo ++$counter1; ?>" rel="tab<?php echo ++$counter2; ?>" class="active"><?php echo esc_html( $term->name ); ?></a></li>
                                <?php endforeach; //foreach ends ?>
                            </ul>
                        </div><!-- .tab-nav -->
                    </div><!-- .row tab-products -->
                </div><!-- .container -->
            </div><!-- .tab-headers -->
            <div class="container">
                <div class="row">
                <div class="tabs-entry col-12">
                    <?php 
                        $counter1 = 0;
                        $category_id = get_theme_mod( 'store_expert_select_product_categories' );
                        $category_ids = explode (",", $category_id);
                        $columns = get_theme_mod( 'store_expert_product_by_categories_columns', 5 );
                        $prod_count = get_theme_mod( 'store_expert_product_by_categories_counts', 10 );
                        foreach( $category_ids as $category_newids ) : 
                    ?>
                        <div id="tab<?php echo ++$counter1; ?>" class="tab-content">
                            <?php echo do_shortcode( '[products columns="'.absint( $columns ).'" limit="'.absint( $prod_count ).'" category="'.esc_html( $category_newids ).'"]' ); ?>                          
                        </div>
                        
                    <?php endforeach; //foreach ends ?>
                </div>
                </div>
            </div><!-- .container -->
            </div>
        </div><!-- .tab-wrapper -->
    </section><!-- #tab-products -->
    <?php 
    endif; 
    endif;

    }

}
add_action( 'store_expert_home_tab_product_block_hook', 'store_expert_home_tab_product_block', 0 );