<?php 
    echo wkp_check_and_show_alert_for_dependent_plugin('woocommerce', 'woocommerce.php', 'free');

    if(wkp_check_dependent_plugin('woocommerce', 'woocommerce.php')):
        /**
         * check if single product page 
         * and single page
         */
        if( is_product() ):
            $cat_list = get_the_terms(get_the_ID(), 'product_cat');
            $cat_count = count($cat_list);
            
            // $post_terms = wp_get_post_terms(get_the_ID(), 'product_cat');
            if($cat_list):
            ?>
            <div class="single-product-category-wrapper">
                <span class="cat-label"><?php echo $category_layout_label ? $category_layout_label : 'Cateogory:' ?> </span> 

                <?php if('list' === $cat_layout):?>
                    <?php foreach($cat_list as $key => $cat):?>
                        <a style="margin:0px 1px;" href="<?php echo get_term_link($cat->term_id);?>"><?php echo  $cat->name;?>
                        <?php echo ($key == ($cat_count-1)) ? '' : ', '; ?>
                        </a>
                    <?php endforeach;?>
                <?php endif;?>
                
                <?php if('grid' === $cat_layout): ?>
                    <div class="category-grid" style="display:grid;grid-template-columns:repeat(<?php echo $category_column? $category_column : '3'; ?>, 1fr);">
                    <?php  foreach($cat_list as $cat): ?>
                        <div class="category-grid-wrapper">
                            <div class="cat-thumb-image">
                                <style>
                                    .woo-single-product-categories .single-product-category-wrapper .cat-thumb-image img{
                                        object-fit: <?php echo $cat_thumb_style; ?>
                                    }
                                </style>
                                <?php 
                                $thumb_id = get_term_meta( $cat->term_id, 'thumbnail_id', true );
                                $term_img_url = wp_get_attachment_url(  $thumb_id );
                                $term_img = wp_get_attachment_image(  $thumb_id, 'thumbnail' );
                                // $woo_placeholder_img = wc_placeholder_img_src(  'thumbnail' );
                                $woo_placeholder_img = wc_placeholder_img(  'thumbnail' );
                                if($term_img){
                                    echo $term_img;
                                }else{
                                    echo $woo_placeholder_img;
                                }
                                ?>
                            </div>
                            <div class="cat-info-wrapper">
                                <a href="<?php echo get_term_link($cat->term_id); ?>">
                                    <span class="cat-name"><?php echo $cat->name; ?></span>
                                    <?php if($show_category_count): ?>
                                    <span class="cat-count"><?php echo '('.$cat->count.')'; ?></span>
                                    <?php endif; ?>
                                </a>
                            </div>
                        </div>
                    <?php endforeach; ?>
                    </div>
                <?php endif; ?>
            </div>
            <?php
            else:
                echo '<h4 style="background:#eee;font-size:14px;color:#a19f9f;padding:10px;">Please assign this product to a category</h4>';    
        endif;

        else:
            echo '<h2 style="border:solid 5px red; padding:30px;">This element only works for WooCommerce Single Product Page</h2>';
        endif;
    endif;
?>