<?php

 /*End Testimonials*/

function faqShortcode($isHome = 0) {
    global $query;

    $args = array('post_type' => 'faq');

    if (!empty($pageId)) {
        $args['page_id'] = absint($pageId);
    } else {
        $args['paged'] = max(1, get_query_var('paged'));
    }

    if(!empty($isHome) && $isHome == 1){
        $cols = get_theme_mod('faq_section_npp_count', 2);
        $cols++;
        $args['posts_per_page'] = $cols;
    }else{
        $args['posts_per_page'] = (!empty($args['posts_per_page'])) ? $args['posts_per_page'] : -1;
         // $cols = 5;
    }
    $faqPageId = get_theme_mod('faq_section_page_link');
    $query = new WP_Query($args);
    ob_start();
    // print_r($query);
    echo '<div class="faq">';
    if ($query->have_posts()){
        while ($query->have_posts()) : $query->the_post();
            $post = get_post();
            ?>
            <div class="row">
                    <div class="col-md-12 faq-content padding0 wow fadeInLeft">
                    <h6 class="faq-title"><?php the_title(); ?></h6>
                    <div class="faq-description">
                        <p><?php
                            if(!empty($isHome) && $isHome==1){
                                if (has_excerpt()) {
                                    echo get_the_excerpt();
                                } else {
                                    //echo lz_fitness_excerpt(get_the_content(),300);
                                     echo get_the_content();
                                }
                                // if(!empty($faqPageId)){
                                //     echo '<a href="'.get_permalink($faqPageId).'">Read More..</a>';
                                // }else{
                                //     echo '<a href="'.get_permalink($faqPageId).'">Read More..</a>';
                                // }
                            }else{
                                echo get_the_content();
                            }?>
                        </p>
                    </div> 
                </div>
            </div>
            <?php
        endwhile;
    }else{
        for($i=0; $i<$cols; $i++){
            ?>
            <div class="row">
                <div class="col-md-12 faq-content padding0">
                    <h6 class="faq-title">Lorem Ipsum is simply dummy text of the printing and typesetting?</h6>
                    <div class="faq-description">
                        <p><?php
                            if(!empty($isHome) && $isHome==1){
                                ?>
                                Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. Lorem Ipsum is simply dummy text of the printing  typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s.
                                <br>
                                <?php
                                // if(!empty($faqPageId)){
                                //     echo '<a href="'.get_permalink($faqPageId).'">Read More..</a>';
                                // }else{
                                //     echo '<a href="'.get_permalink($faqPageId).'">Read More..</a>';
                                // }
                            }else{
                                ?>
                                Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. Lorem Ipsum is simply dummy text of the printing  typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s.

                                Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. Lorem Ipsum is simply dummy text of the printing  typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s.
                                <?php
                            }?>
                        </p>
                    </div>  
                </div>
            </div>
            <?php
        }
    }
        echo '</div>';
        ?>

        <script>
            $(function(){
                $('.faq-description').hide();
                $('.faq-title').on('click', function(){
                    $('.faq-description.active').slideToggle(500).removeClass('active');
                    $(this).next().slideToggle(500).toggleClass('active');
                    
                });
            });
        </script>
        <?php
        $text = ob_get_contents();
        ob_clean();
        ob_end_flush();
    wp_reset_postdata();
    // echo $text;
    return $text;
}



//adding a shortcode for the FAQ list 
add_shortcode('FAQS', 'faqShortcode');

/**
 * Get list of all categories from woocommerce theme
 * @param int $isObject return type in array of object default is true
 * @param int $itemPerPagenumber of items per page default -1
 * @param int $isParents to show the only parents default '0'
 * @param int $orderby name of field ordeing with default 'name'
 * @param int $order assending of deseinging default 'ASC'
 * @param int $hideEmpty show the empty categories or not default 'false'
 * @return Array/Object 
 * @author Luzuk 
 * @since version 1.0
 **/
function getWooCategories($isObject = true, $id=0, $isParents = 0, $itemPerPagenumber = -1, $orderby='name', $order='ASC', $hideEmpty = false){
    $categories = array();
    // echo 'asdlkfjoasdoh';
    $args = array(
        'taxonomy' => 'product_cat',
        'orderby' => $orderby, // 'slug',
        'hide_empty' => $hideEmpty,
        'number'=> 0
    );

    if($isParents == 0 ){
        $args['parent'] = $isParents;
    }

    if(!empty($id) && $id >0 ){
        $args['term_taxonomy_id'] = $id;
    }
    $parent_terms = get_terms($args);
    // print_r($parent_terms);
    foreach ($parent_terms as $pterm) {
        if($isObject === true){
            $categories[] = $pterm;
        }elseif(!empty($pterm->term_id)){
            $categories[$pterm->term_id] = $pterm->name;
            // echo '&*&*&';
        }
        
    }
    // print_r($categories);
    return $categories;
}    