<?php


use Elementor\Widget_Base;
use Elementor\Controls_Manager;

if (!defined('ABSPATH')) exit; // Exit if accessed directly


class Digikalaproductscategoryonekaveh extends Widget_Base
{

    public function get_name()
    {
        return 'digikalaproductscategoryonekaveh';
    }

    public function get_title()
    {
        return esc_html__('Digikala Category Style One Widget', 'kavehTheme');
    }

    public function get_icon()
    {
        return 'eicon-archive-posts';
    }

    public function get_categories()
    {
        return ['kavehelements'];
    }

    protected function register_controls()
    {

        $this->start_controls_section(
            'content1digikalaproductscategoryonekaveh',
            [
                'label' => esc_html__('First Column Content', 'kavehTheme'),
                'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
            ]
        );

        $this->add_control(
            'title1digikalaproductscategoryonekaveh',
            [
                'label' => esc_html__('Title (Category Name)', 'kavehTheme'),
                'type' => \Elementor\Controls_Manager::TEXT,
                'default' => esc_html__('Mobile Phone', 'kavehTheme'),

            ]
        );
        $this->add_control(
            'tagheading1digikalaproductscategoryonekaveh',
            [
                'label' => esc_html__('Title Tag', 'kavehTheme'),
                'type' => \Elementor\Controls_Manager::SELECT,
                'default' => 'div',
                'options' => [
                    'H1' => esc_html__('H1', 'kavehTheme'),
                    'H2' => esc_html__('H2', 'kavehTheme'),
                    'H3' => esc_html__('H3', 'kavehTheme'),
                    'H4' => esc_html__('H4', 'kavehTheme'),
                    'H5' => esc_html__('H5', 'kavehTheme'),
                    'H6' => esc_html__('H6', 'kavehTheme'),
                    'p' => esc_html__('p', 'kavehTheme'),
                    'div' => esc_html__('div', 'kavehTheme'),
                    'span' => esc_html__('span', 'kavehTheme'),
                ],
            ]
        );

        $this->add_control(
            'subtitle1digikalaproductscategoryonekaveh',
            [
                'label' => esc_html__('Subtitle', 'kavehTheme'),
                'type' => \Elementor\Controls_Manager::TEXT,
                'default' => esc_html__('Based on your visits', 'kavehTheme'),

            ]
        );

        $options = array();
        $orderby = 'name';
        $order = 'asc';
        $hide_empty = true;
        $cat_args = array(
            'orderby' => $orderby,
            'order' => $order,
            'hide_empty' => $hide_empty,
        );

        $product_categories = get_terms('product_cat', $cat_args);

        foreach ($product_categories as $key => $category) {
            $options[$category->term_id] = $category->name;
        }
        $this->add_control(
            'catproducts1digikalaproductscategoryonekaveh',
            [
                'label' => esc_html__('Select Category', 'kavehTheme'),
                'type' => \Elementor\Controls_Manager::SELECT2,
                'multiple' => true,
                'options' => $options,
            ]
        );

        $this->add_control(
            'button1digikalaproductscategoryonekaveh',
            [
                'label' => esc_html__('Button Title', 'kavehTheme'),
                'type' => \Elementor\Controls_Manager::TEXT,
                'default' => esc_html__('View', 'kavehTheme'),
            ]
        );

        $this->add_control(
            'buttonlink1digikalaproductscategoryonekaveh',
            [
                'label' => esc_html__('Button Link', 'kavehTheme'),
                'type' => \Elementor\Controls_Manager::TEXT,
                'default' => esc_html__('#', 'kavehTheme'),

            ]
        );

        $this->end_controls_section();

        $this->start_controls_section(
            'content2digikalaproductscategoryonekaveh',
            [
                'label' => esc_html__('Second Column Content', 'kavehTheme'),
                'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
            ]
        );

        $this->add_control(
            'title2digikalaproductscategoryonekaveh',
            [
                'label' => esc_html__('Title (Category Name)', 'kavehTheme'),
                'type' => \Elementor\Controls_Manager::TEXT,
                'default' => esc_html__('Mobile Phone', 'kavehTheme'),

            ]
        );
        $this->add_control(
            'tagheading2digikalaproductscategoryonekaveh',
            [
                'label' => esc_html__('Title Tag', 'kavehTheme'),
                'type' => \Elementor\Controls_Manager::SELECT,
                'default' => 'div',
                'options' => [
                    'H1' => esc_html__('H1', 'kavehTheme'),
                    'H2' => esc_html__('H2', 'kavehTheme'),
                    'H3' => esc_html__('H3', 'kavehTheme'),
                    'H4' => esc_html__('H4', 'kavehTheme'),
                    'H5' => esc_html__('H5', 'kavehTheme'),
                    'H6' => esc_html__('H6', 'kavehTheme'),
                    'p' => esc_html__('p', 'kavehTheme'),
                    'div' => esc_html__('div', 'kavehTheme'),
                    'span' => esc_html__('span', 'kavehTheme'),
                ],
            ]
        );

        $this->add_control(
            'subtitle2digikalaproductscategoryonekaveh',
            [
                'label' => esc_html__('Subtitle', 'kavehTheme'),
                'type' => \Elementor\Controls_Manager::TEXT,
                'default' => esc_html__('Based on your visits', 'kavehTheme'),

            ]
        );

        $options = array();
        $orderby = 'name';
        $order = 'asc';
        $hide_empty = true;
        $cat_args = array(
            'orderby' => $orderby,
            'order' => $order,
            'hide_empty' => $hide_empty,
        );


        foreach ($product_categories as $key => $category) {
            $options[$category->term_id] = $category->name;
        }
        $this->add_control(
            'catproducts2digikalaproductscategoryonekaveh',
            [
                'label' => esc_html__('Select Category', 'kavehTheme'),
                'type' => \Elementor\Controls_Manager::SELECT2,
                'multiple' => true,
                'options' => $options,
            ]
        );

        $this->add_control(
            'button2digikalaproductscategoryonekaveh',
            [
                'label' => esc_html__('Button Title', 'kavehTheme'),
                'type' => \Elementor\Controls_Manager::TEXT,
                'default' => esc_html__('View', 'kavehTheme'),
            ]
        );

        $this->add_control(
            'buttonlink2digikalaproductscategoryonekaveh',
            [
                'label' => esc_html__('Button Link', 'kavehTheme'),
                'type' => \Elementor\Controls_Manager::TEXT,
                'default' => esc_html__('#', 'kavehTheme'),

            ]
        );

        $this->end_controls_section();

        $this->start_controls_section(
            'content3digikalaproductscategoryonekaveh',
            [
                'label' => esc_html__('Third Column Content', 'kavehTheme'),
                'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
            ]
        );

        $this->add_control(
            'title3digikalaproductscategoryonekaveh',
            [
                'label' => esc_html__('Title (Category Name)', 'kavehTheme'),
                'type' => \Elementor\Controls_Manager::TEXT,
                'default' => esc_html__('Mobile Phone', 'kavehTheme'),

            ]
        );
        $this->add_control(
            'tagheading3digikalaproductscategoryonekaveh',
            [
                'label' => esc_html__('Title Tag', 'kavehTheme'),
                'type' => \Elementor\Controls_Manager::SELECT,
                'default' => 'div',
                'options' => [
                    'H1' => esc_html__('H1', 'kavehTheme'),
                    'H2' => esc_html__('H2', 'kavehTheme'),
                    'H3' => esc_html__('H3', 'kavehTheme'),
                    'H4' => esc_html__('H4', 'kavehTheme'),
                    'H5' => esc_html__('H5', 'kavehTheme'),
                    'H6' => esc_html__('H6', 'kavehTheme'),
                    'p' => esc_html__('p', 'kavehTheme'),
                    'div' => esc_html__('div', 'kavehTheme'),
                    'span' => esc_html__('span', 'kavehTheme'),
                ],
            ]
        );

        $this->add_control(
            'subtitle3digikalaproductscategoryonekaveh',
            [
                'label' => esc_html__('Subtitle', 'kavehTheme'),
                'type' => \Elementor\Controls_Manager::TEXT,
                'default' => esc_html__('Based on your visits', 'kavehTheme'),

            ]
        );

        $options = array();
        $orderby = 'name';
        $order = 'asc';
        $hide_empty = true;
        $cat_args = array(
            'orderby' => $orderby,
            'order' => $order,
            'hide_empty' => $hide_empty,
        );


        foreach ($product_categories as $key => $category) {
            $options[$category->term_id] = $category->name;
        }
        $this->add_control(
            'catproducts3digikalaproductscategoryonekaveh',
            [
                'label' => esc_html__('Select Category', 'kavehTheme'),
                'type' => \Elementor\Controls_Manager::SELECT2,
                'multiple' => true,
                'options' => $options,
            ]
        );

        $this->add_control(
            'button3digikalaproductscategoryonekaveh',
            [
                'label' => esc_html__('Button Title', 'kavehTheme'),
                'type' => \Elementor\Controls_Manager::TEXT,
                'default' => esc_html__('View', 'kavehTheme'),
            ]
        );

        $this->add_control(
            'buttonlink3digikalaproductscategoryonekaveh',
            [
                'label' => esc_html__('Button Link', 'kavehTheme'),
                'type' => \Elementor\Controls_Manager::TEXT,
                'default' => esc_html__('#', 'kavehTheme'),

            ]
        );

        $this->end_controls_section();

        $this->start_controls_section(
            'content4digikalaproductscategoryonekaveh',
            [
                'label' => esc_html__('Fourth Column Content', 'kavehTheme'),
                'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
            ]
        );

        $this->add_control(
            'title4digikalaproductscategoryonekaveh',
            [
                'label' => esc_html__('Title (Category Name)', 'kavehTheme'),
                'type' => \Elementor\Controls_Manager::TEXT,
                'default' => esc_html__('Mobile Phone', 'kavehTheme'),

            ]
        );
        $this->add_control(
            'tagheading4digikalaproductscategoryonekaveh',
            [
                'label' => esc_html__('Title Tag', 'kavehTheme'),
                'type' => \Elementor\Controls_Manager::SELECT,
                'default' => 'div',
                'options' => [
                    'H1' => esc_html__('H1', 'kavehTheme'),
                    'H2' => esc_html__('H2', 'kavehTheme'),
                    'H3' => esc_html__('H3', 'kavehTheme'),
                    'H4' => esc_html__('H4', 'kavehTheme'),
                    'H5' => esc_html__('H5', 'kavehTheme'),
                    'H6' => esc_html__('H6', 'kavehTheme'),
                    'p' => esc_html__('p', 'kavehTheme'),
                    'div' => esc_html__('div', 'kavehTheme'),
                    'span' => esc_html__('span', 'kavehTheme'),
                ],
            ]
        );

        $this->add_control(
            'subtitle4digikalaproductscategoryonekaveh',
            [
                'label' => esc_html__('Subtitle', 'kavehTheme'),
                'type' => \Elementor\Controls_Manager::TEXT,
                'default' => esc_html__('Based on your visits', 'kavehTheme'),

            ]
        );

        $options = array();
        $orderby = 'name';
        $order = 'asc';
        $hide_empty = true;
        $cat_args = array(
            'orderby' => $orderby,
            'order' => $order,
            'hide_empty' => $hide_empty,
        );


        foreach ($product_categories as $key => $category) {
            $options[$category->term_id] = $category->name;
        }
        $this->add_control(
            'catproducts4digikalaproductscategoryonekaveh',
            [
                'label' => esc_html__('Select Category', 'kavehTheme'),
                'type' => \Elementor\Controls_Manager::SELECT2,
                'multiple' => true,
                'options' => $options,
            ]
        );

        $this->add_control(
            'button4digikalaproductscategoryonekaveh',
            [
                'label' => esc_html__('Button Title', 'kavehTheme'),
                'type' => \Elementor\Controls_Manager::TEXT,
                'default' => esc_html__('View', 'kavehTheme'),
            ]
        );

        $this->add_control(
            'buttonlink4digikalaproductscategoryonekaveh',
            [
                'label' => esc_html__('Button Link', 'kavehTheme'),
                'type' => \Elementor\Controls_Manager::TEXT,
                'default' => esc_html__('#', 'kavehTheme'),

            ]
        );

        $this->end_controls_section();

        $this->start_controls_section(
            'style_digikalaproductscategoryonekaveh',
            [
                'label' => esc_html__('Title Style', 'kavehTheme'),
                'tab' => \Elementor\Controls_Manager::TAB_STYLE,
            ]
        );
        $this->add_control(
            'titlecolordigikalaproductscategoryonekaveh',
            [
                'label' => esc_html__('Title Color', 'kavehTheme'),
                'type' => \Elementor\Controls_Manager::COLOR,
                'default' => '#23254e',
                'selectors' => [
                    '{{WRAPPER}} .products-category-kala-title' => 'color: {{VALUE}}',
                ],
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Typography::get_type(),
            [
                'name' => 'title_digikalaproductscategoryonekaveh',
                'label' => esc_html__('Title Typography', 'kavehTheme'),
                'selector' => '{{WRAPPER}} .products-category-kala-title',
            ]
        );

        $this->add_control(
            'subtitlecolordigikalaproductscategoryonekaveh',
            [
                'label' => esc_html__('Subtitle Color', 'kavehTheme'),
                'type' => \Elementor\Controls_Manager::COLOR,
                'default' => '#767790',
                'selectors' => [
                    '{{WRAPPER}} .products-category-kala-sub-title' => 'color: {{VALUE}}',
                ],
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Typography::get_type(),
            [
                'name' => 'title2_digikalaproductscategoryonekaveh',
                'label' => esc_html__('Subtitle Typography', 'kavehTheme'),
                'selector' => '{{WRAPPER}} .products-category-kala-sub-title',
            ]
        );

        $this->end_controls_section();


        $this->start_controls_section(
            'style2_digikalaproductscategoryonekaveh',
            [
                'label' => esc_html__('Button Style', 'kavehTheme'),
                'tab' => \Elementor\Controls_Manager::TAB_STYLE,
            ]
        );

        $this->add_group_control(
            \Elementor\Group_Control_Typography::get_type(),
            [
                'name' => 'button_digikalaproductscategoryonekaveh',
                'label' => esc_html__('Button Text Typography', 'kavehTheme'),
                'selector' => '{{WRAPPER}} .products-category-kala .link-more',
            ]
        );

        $this->add_control(
            'buttoncolordigikalaproductscategoryonekaveh',
            [
                'label' => esc_html__('Button Text Color', 'kavehTheme'),
                'type' => \Elementor\Controls_Manager::COLOR,
                'default' => '#19bfd3',
                'selectors' => [
                    '{{WRAPPER}} .products-category-kala .link-more' => 'color: {{VALUE}}',
                ],
            ]
        );

        $this->end_controls_section();


        $this->start_controls_section(
            'style4_boxdigikalaproductscategoryonekaveh',
            [
                'label' => esc_html__('Main Box Style', 'kavehTheme'),
                'tab' => \Elementor\Controls_Manager::TAB_STYLE,
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Border::get_type(),
            [
                'name' => 'borderboxdigikalaproductscategoryonekavehveh',
                'selector' => '{{WRAPPER}} .products-category-kala-wrapper'
            ]
        );
        $this->add_control(
            'boxradiusdigikalaproductscategoryonekaveh',
            [
                'label' => esc_html__('Border Radius', 'kavehTheme'),
                'type' => \Elementor\Controls_Manager::DIMENSIONS,
                'size_units' => ['px'],
                'selectors' => [
                    '{{WRAPPER}} .products-category-kala-wrapper' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );

        $this->add_control(
            'colorborderdigikalaproductscategoryonekaveh',
            [
                'label' => esc_html__('Column and Image Separator Color', 'kavehTheme'),
                'type' => \Elementor\Controls_Manager::COLOR,
                'default' => '#f1f2f4',
                'selectors' => [
                    '{{WRAPPER}} .products-category-kala-wrapper>.row>*:not(:last-child)' => 'border-left: 1px solid {{VALUE}}',
                    '{{WRAPPER}} .products-category-kala-wrapper>.row>*>.row>*:nth-child(1)' => 'border-left: 1px solid {{VALUE}}',
                    '{{WRAPPER}} .products-category-kala-wrapper>.row>*>.row>*:nth-child(3)' => 'border-left: 1px solid {{VALUE}}',
                    '{{WRAPPER}} .products-category-kala-wrapper>.row>*>.row>*:nth-child(n+3)' => 'border-top: 1px solid {{VALUE}}',
                ],
            ]
        );


        $this->end_controls_section();

    }


    protected function render()
    {
        $settings = $this->get_settings_for_display();
        $clsid = $this->get_id();
        ?>


        <!-- Start Products Category -->
        <section class="products-category-kala">
            <div class="container">
                <div class="products-category-kala-wrapper">
                    <div class="row m-0">
                        <div class="col-sm-6 col-lg-3">
                            <<?php echo esc_attr($settings['tagheading1digikalaproductscategoryonekaveh']); ?>
                            class="products-category-kala-title ">
                            <?php echo esc_html($settings['title1digikalaproductscategoryonekaveh']); ?>
                        </<?php echo esc_attr($settings['tagheading1digikalaproductscategoryonekaveh']); ?>>
                        <div class="products-category-kala-sub-title mb-2"><?php echo esc_html($settings['subtitle1digikalaproductscategoryonekaveh']); ?></div>
                        <div class="row m-0">
                            <?php

                            // WP_Query args
                            $cat_query_args = array(
                                'post_type' => array('product'),
'post_status' => array('publish'),
                                'posts_per_page' => 4,
                                'order' => 'DESC',
                                'orderby' => 'date',
                                'tax_query' => array(
                                    array(
                                        "taxonomy" => "product_cat",
                                        "field" => "term_id",
                                        "terms" => $settings['catproducts1digikalaproductscategoryonekaveh'],
                                    ),
                                ),
                                'meta_query' => array(
                                    array(
                                        'key' => '_stock_status',
                                        'value' => 'outofstock',
                                        'compare' => 'NOT IN',
                                    ),
                                ),
                            );

                            // The Query
                            $pcat_query = new \WP_Query($cat_query_args);

                            // The Loop
                            if ($pcat_query->have_posts()) :?>
                                <?php while ($pcat_query->have_posts()) :
                                    $pcat_query->the_post(); ?>
                                    <div class="col-6 p-0">
                                        <a href="<?php the_permalink(); ?>"
                                           class="products-category-kala-item d-block p-2">
                                            <img src="<?php the_post_thumbnail_url('thumbnail'); ?>"
                                                 alt="<?php the_title(); ?>"
                                                 width="126"
                                                 height="126" class="d-block w-100">
                                        </a>
                                    </div>
                                <?php
                                endwhile;
                                // Reset Original Post Data
                                wp_reset_postdata();
                                ?>
                            <?php endif; ?>
                        </div>
                        <a href="<?php echo esc_url($settings['buttonlink1digikalaproductscategoryonekaveh']); ?>"
                           class="link-more d-flex align-items-center justify-content-center">
                            <?php echo esc_html($settings['button1digikalaproductscategoryonekaveh']); ?>
                            <i class="icon-angle-left ms-2"></i>
                        </a>
                    </div>
                    <div class="col-sm-6 col-lg-3">
                        <<?php echo esc_attr($settings['tagheading2digikalaproductscategoryonekaveh']); ?>
                        class="products-category-kala-title ">
                        <?php echo esc_html($settings['title2digikalaproductscategoryonekaveh']); ?>
                    </<?php echo esc_attr($settings['tagheading2digikalaproductscategoryonekaveh']); ?>>
                    <div class="products-category-kala-sub-title mb-2"><?php echo esc_html($settings['subtitle2digikalaproductscategoryonekaveh']); ?></div>
                    <div class="row m-0">
                        <?php

                        // WP_Query args
                        $cat_query_args = array(
                            'post_type' => array('product'),
'post_status' => array('publish'),
                            'posts_per_page' => 4,
                            'order' => 'DESC',
                            'orderby' => 'date',
                            'tax_query' => array(
                                array(
                                    "taxonomy" => "product_cat",
                                    "field" => "term_id",
                                    "terms" => $settings['catproducts2digikalaproductscategoryonekaveh'],
                                ),
                            ),
                            'meta_query' => array(
                                array(
                                    'key' => '_stock_status',
                                    'value' => 'outofstock',
                                    'compare' => 'NOT IN',
                                ),
                            ),
                        );

                        // The Query
                        $pcat_query = new \WP_Query($cat_query_args);

                        // The Loop
                        if ($pcat_query->have_posts()) :?>
                            <?php while ($pcat_query->have_posts()) :
                                $pcat_query->the_post(); ?>
                                <div class="col-6 p-0">
                                    <a href="<?php the_permalink(); ?>"
                                       class="products-category-kala-item d-block p-2">
                                        <img src="<?php the_post_thumbnail_url('thumbnail'); ?>"
                                             alt="<?php the_title(); ?>"
                                             width="126"
                                             height="126" class="d-block w-100">
                                    </a>
                                </div>
                            <?php
                            endwhile;
                            // Reset Original Post Data
                            wp_reset_postdata();
                            ?>
                        <?php endif; ?>
                    </div>
                    <a href="<?php echo esc_url($settings['buttonlink2digikalaproductscategoryonekaveh']); ?>"
                       class="link-more d-flex align-items-center justify-content-center">
                        <?php echo esc_html($settings['button2digikalaproductscategoryonekaveh']); ?>
                        <i class="icon-angle-left ms-2"></i>
                    </a>
                </div>
                <div class="col-sm-6 col-lg-3">
                    <<?php echo esc_attr($settings['tagheading3digikalaproductscategoryonekaveh']); ?>
                    class="products-category-kala-title ">
                    <?php echo esc_html($settings['title3digikalaproductscategoryonekaveh']); ?>
                </<?php echo esc_attr($settings['tagheading3digikalaproductscategoryonekaveh']); ?>>
                <div class="products-category-kala-sub-title mb-2"><?php echo esc_html($settings['subtitle3digikalaproductscategoryonekaveh']); ?></div>
                <div class="row m-0">
                    <?php

                    // WP_Query args
                    $cat_query_args = array(
                        'post_type' => array('product'),
'post_status' => array('publish'),
                        'posts_per_page' => 4,
                        'order' => 'DESC',
                        'orderby' => 'date',
                        'tax_query' => array(
                            array(
                                "taxonomy" => "product_cat",
                                "field" => "term_id",
                                "terms" => $settings['catproducts3digikalaproductscategoryonekaveh'],
                            ),
                        ),
                        'meta_query' => array(
                            array(
                                'key' => '_stock_status',
                                'value' => 'outofstock',
                                'compare' => 'NOT IN',
                            ),
                        ),
                    );

                    // The Query
                    $pcat_query = new \WP_Query($cat_query_args);

                    // The Loop
                    if ($pcat_query->have_posts()) :?>
                        <?php while ($pcat_query->have_posts()) :
                            $pcat_query->the_post(); ?>
                            <div class="col-6 p-0">
                                <a href="<?php the_permalink(); ?>"
                                   class="products-category-kala-item d-block p-2">
                                    <img src="<?php the_post_thumbnail_url('thumbnail'); ?>"
                                         alt="<?php the_title(); ?>"
                                         width="126"
                                         height="126" class="d-block w-100">
                                </a>
                            </div>
                        <?php
                        endwhile;
                        // Reset Original Post Data
                        wp_reset_postdata();
                        ?>
                    <?php endif; ?>
                </div>
                <a href="<?php echo esc_url($settings['buttonlink3digikalaproductscategoryonekaveh']); ?>"
                   class="link-more d-flex align-items-center justify-content-center">
                    <?php echo esc_html($settings['button3digikalaproductscategoryonekaveh']); ?>
                    <i class="icon-angle-left ms-2"></i>
                </a>
            </div>
            <div class="col-sm-6 col-lg-3">
                <<?php echo esc_attr($settings['tagheading4digikalaproductscategoryonekaveh']); ?>
                class="products-category-kala-title ">
                <?php echo esc_html($settings['title4digikalaproductscategoryonekaveh']); ?>
            </<?php echo esc_attr($settings['tagheading4digikalaproductscategoryonekaveh']); ?>>
            <div class="products-category-kala-sub-title mb-2"><?php echo esc_html($settings['subtitle4digikalaproductscategoryonekaveh']); ?></div>
            <div class="row m-0">
                <?php

                // WP_Query args
                $cat_query_args = array(
                    'post_type' => array('product'),
'post_status' => array('publish'),
                    'posts_per_page' => 4,
                    'order' => 'DESC',
                    'orderby' => 'date',
                    'tax_query' => array(
                        array(
                            "taxonomy" => "product_cat",
                            "field" => "term_id",
                            "terms" => $settings['catproducts4digikalaproductscategoryonekaveh'],
                        ),
                    ),
                    'meta_query' => array(
                        array(
                            'key' => '_stock_status',
                            'value' => 'outofstock',
                            'compare' => 'NOT IN',
                        ),
                    ),
                );

                // The Query
                $pcat_query = new \WP_Query($cat_query_args);

                // The Loop
                if ($pcat_query->have_posts()) :?>
                    <?php while ($pcat_query->have_posts()) :
                        $pcat_query->the_post(); ?>
                        <div class="col-6 p-0">
                            <a href="<?php the_permalink(); ?>"
                               class="products-category-kala-item d-block p-2">
                                <img src="<?php the_post_thumbnail_url('thumbnail'); ?>"
                                     alt="<?php the_title(); ?>"
                                     width="126"
                                     height="126" class="d-block w-100">
                            </a>
                        </div>
                    <?php
                    endwhile;
                    // Reset Original Post Data
                    wp_reset_postdata();
                    ?>
                <?php endif; ?>
            </div>
            <a href="<?php echo esc_url($settings['buttonlink4digikalaproductscategoryonekaveh']); ?>"
               class="link-more d-flex align-items-center justify-content-center">
                <?php echo esc_html($settings['button4digikalaproductscategoryonekaveh']); ?>
                <i class="icon-angle-left ms-2"></i>
            </a>
            </div>
            </div>
            </div>
            </div>
        </section>
        <!-- End Products Category -->
        <?php
    }
}
