File: /home/frenchy/refonte2023/wordpress/wp-content/themes/gimont/elementor/widgets/product-slider.php
<?php
use Elementor\Widget_Base;
use Elementor\Controls_Manager;
use Elementor\Group_Control_Typography;
use Elementor\Group_Control_Border;
use Elementor\Group_Control_Box_Shadow;
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( !gimont_is_woo_active() ) {
return ;
}
class Gimont_Elementor_Product_Slider extends Widget_Base {
public function get_name() {
return 'gimont_elementor_product_slider';
}
public function get_title() {
return esc_html__( 'Product Slider', 'gimont' );
}
public function get_icon() {
return 'eicon-products';
}
public function get_categories() {
return [ 'gimont' ];
}
public function get_script_depends() {
return [ 'gimont-elementor-product-slider' ];
}
protected function register_controls() {
$this->start_controls_section(
'section_product_slider_content',
[
'label' => esc_html__( 'Content', 'gimont' ),
]
);
$this->add_control(
'show_featured',
[
'label' => esc_html__( 'Only Show Featured', 'gimont' ),
'type' => \Elementor\Controls_Manager::SWITCHER,
'label_on' => esc_html__( 'Show', 'gimont' ),
'label_off' => esc_html__( 'Hide', 'gimont' ),
'default' => 'no',
]
);
$args_query = [
'taxonomy' => 'product_cat',
'orderby' => 'name',
'order' => 'ASC'
];
$categories = get_categories( $args_query );
$args_category = array( 'all' => esc_html__( 'All', 'gimont' ) );
if ( $categories && is_array( $categories ) ) {
foreach ( $categories as $category ) {
$args_category[$category->slug] = $category->cat_name;
}
}
$this->add_control(
'categories',
[
'label' => esc_html__( 'Select Category', 'gimont' ),
'type' => \Elementor\Controls_Manager::SELECT,
'default' => 'all',
'options' => $args_category,
]
);
$this->add_control(
'posts_per_page',
[
'label' => esc_html__( 'Posts Per Page', 'gimont' ),
'type' => \Elementor\Controls_Manager::NUMBER,
'default' => 5,
]
);
$this->add_control(
'limit',
[
'label' => esc_html__( 'Limit Title Words', 'gimont' ),
'type' => \Elementor\Controls_Manager::NUMBER,
'default' => 3,
'min' => 1,
'max' => 5
]
);
$this->add_control(
'short_des_limit',
[
'label' => esc_html__( 'Limit Short Description Words', 'gimont' ),
'type' => \Elementor\Controls_Manager::NUMBER,
'default' => 7,
'min' => 2,
'max' => 15
]
);
$this->add_control(
'orderby',
[
'label' => esc_html__( 'Order By', 'gimont' ),
'type' => \Elementor\Controls_Manager::SELECT,
'default' => 'ID',
'options' => [
'title' => esc_html__( 'Title', 'gimont' ),
'ID' => esc_html__( 'ID', 'gimont' ),
'date' => esc_html__( 'Date', 'gimont' ),
'rand' => esc_html__( 'Random', 'gimont' ),
],
]
);
$this->add_control(
'order',
[
'label' => esc_html__( 'Order', 'gimont' ),
'type' => \Elementor\Controls_Manager::SELECT,
'default' => 'DESC',
'options' => [
'ASC' => esc_html__( 'Ascending', 'gimont' ),
'DESC' => esc_html__( 'Descending', 'gimont' ),
],
]
);
$this->add_control(
'category_in',
[
'label' => esc_html__( 'Category In', 'gimont' ),
'type' => Controls_Manager::TEXT,
'description' => esc_html__( 'Enter the product category IDs. IDs are separated by "|". Ex: 1|2|3.', 'gimont' ),
]
);
$this->add_control(
'category_not_in',
[
'label' => esc_html__( 'Category Not In', 'gimont' ),
'type' => Controls_Manager::TEXT,
'description' => esc_html__( 'Enter the product category IDs. IDs are separated by "|". Ex: 1|2|3.', 'gimont' ),
]
);
$this->add_control(
'show_review',
[
'label' => esc_html__( 'Show Review', 'gimont' ),
'type' => \Elementor\Controls_Manager::SWITCHER,
'label_on' => esc_html__( 'Show', 'gimont' ),
'label_off' => esc_html__( 'Hide', 'gimont' ),
'default' => 'yes',
]
);
$this->add_control(
'show_short_des',
[
'label' => esc_html__( 'Show Short Description', 'gimont' ),
'type' => \Elementor\Controls_Manager::SWITCHER,
'label_on' => esc_html__( 'Show', 'gimont' ),
'label_off' => esc_html__( 'Hide', 'gimont' ),
'default' => 'no',
]
);
$this->add_control(
'show_link_to_detail',
[
'label' => esc_html__( 'Show Link to Detail Product', 'gimont' ),
'type' => \Elementor\Controls_Manager::SWITCHER,
'label_on' => esc_html__( 'Show', 'gimont' ),
'label_off' => esc_html__( 'Hide', 'gimont' ),
'default' => 'yes',
]
);
$this->end_controls_section();
/*****************************************************************
START SECTION ADDITIONAL
******************************************************************/
$this->start_controls_section(
'section_additional_options',
[
'label' => esc_html__( 'Additional Options', 'gimont' ),
]
);
$this->add_control(
'margin_items',
[
'label' => esc_html__( 'Margin Right Items', 'gimont' ),
'type' => Controls_Manager::NUMBER,
'default' => 30,
]
);
$this->add_control(
'item_number',
[
'label' => esc_html__( 'Item Number', 'gimont' ),
'type' => Controls_Manager::NUMBER,
'description' => esc_html__( 'Number Item', 'gimont' ),
'default' => 4,
]
);
$this->add_control(
'slides_to_scroll',
[
'label' => esc_html__( 'Slides to Scroll', 'gimont' ),
'type' => Controls_Manager::NUMBER,
'description' => esc_html__( 'Set how many slides are scrolled per swipe.', 'gimont' ),
'default' => 1,
]
);
$this->add_control(
'pause_on_hover',
[
'label' => esc_html__( 'Pause on Hover', 'gimont' ),
'type' => Controls_Manager::SWITCHER,
'default' => 'yes',
'options' => [
'yes' => esc_html__( 'Yes', 'gimont' ),
'no' => esc_html__( 'No', 'gimont' ),
],
'frontend_available' => true,
]
);
$this->add_control(
'infinite',
[
'label' => esc_html__( 'Infinite Loop', 'gimont' ),
'type' => Controls_Manager::SWITCHER,
'default' => 'no',
'options' => [
'yes' => esc_html__( 'Yes', 'gimont' ),
'no' => esc_html__( 'No', 'gimont' ),
],
'frontend_available' => true,
]
);
$this->add_control(
'autoplay',
[
'label' => esc_html__( 'Autoplay', 'gimont' ),
'type' => Controls_Manager::SWITCHER,
'default' => 'yes',
'options' => [
'yes' => esc_html__( 'Yes', 'gimont' ),
'no' => esc_html__( 'No', 'gimont' ),
],
'frontend_available' => true,
]
);
$this->add_control(
'autoplay_speed',
[
'label' => esc_html__( 'Autoplay Speed', 'gimont' ),
'type' => Controls_Manager::NUMBER,
'default' => 3000,
'step' => 500,
'condition' => [
'autoplay' => 'yes',
],
'frontend_available' => true,
]
);
$this->add_control(
'smartspeed',
[
'label' => esc_html__( 'Smart Speed', 'gimont' ),
'type' => Controls_Manager::NUMBER,
'default' => 500,
]
);
$this->add_control(
'dot_control',
[
'label' => esc_html__( 'Show Dots', 'gimont' ),
'type' => Controls_Manager::SWITCHER,
'default' => 'yes',
'options' => [
'yes' => esc_html__( 'Yes', 'gimont' ),
'no' => esc_html__( 'No', 'gimont' ),
],
'frontend_available' => true,
]
);
$this->add_control(
'nav_control',
[
'label' => esc_html__( 'Show Nav', 'gimont' ),
'type' => Controls_Manager::SWITCHER,
'default' => 'no',
'options' => [
'yes' => esc_html__( 'Yes', 'gimont' ),
'no' => esc_html__( 'No', 'gimont' ),
],
'frontend_available' => true,
]
);
$this->end_controls_section();
/**************************** END SECTION ADDITIONAL *********************/
$this->start_controls_section(
'section_product_slider_style',
[
'label' => esc_html__( 'Content', 'gimont' ),
'tab' => Controls_Manager::TAB_STYLE,
]
);
$this->add_control(
'content_background',
[
'label' => esc_html__( 'Background', 'gimont' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .ova-product-slider .product-slider .item-product-slider' => 'background-color: {{VALUE}}',
],
]
);
$this->add_control(
'content_background_hover',
[
'label' => esc_html__( 'Background Hover', 'gimont' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .ova-product-slider .product-slider .item-product-slider:hover' => 'background-color: {{VALUE}}',
],
]
);
$this->add_group_control(
Group_Control_Border::get_type(),
[
'name' => 'content_border',
'label' => esc_html__( 'Border', 'gimont' ),
'selector' => '{{WRAPPER}} .ova-product-slider .product-slider .item-product-slider',
]
);
$this->add_responsive_control(
'content_border_radius',
[
'label' => esc_html__( 'Border Radius', 'gimont' ),
'type' => Controls_Manager::DIMENSIONS,
'size_units' => [ 'px', '%', 'em' ],
'selectors' => [
'{{WRAPPER}} .ova-product-slider .product-slider .item-product-slider' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
],
]
);
$this->add_responsive_control(
'content_padding',
[
'label' => esc_html__( 'Padding', 'gimont' ),
'type' => Controls_Manager::DIMENSIONS,
'size_units' => [ 'px', '%', 'em' ],
'selectors' => [
'{{WRAPPER}} .ova-product-slider .product-slider .item-product-slider' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
],
]
);
$this->end_controls_section();
// Sale Badge
$this->start_controls_section(
'section_sale_badge_style',
[
'label' => esc_html__( 'Sale Badge', 'gimont' ),
'tab' => Controls_Manager::TAB_STYLE,
]
);
$this->add_control(
'sale_badge_size',
[
'label' => esc_html__( 'Size', 'gimont' ),
'type' => Controls_Manager::SLIDER,
'size_units' => [ 'px' ],
'range' => [
'px' => [
'min' => 55,
'max' => 120,
'step' => 1,
]
],
'selectors' => [
'{{WRAPPER}} .ova-product-slider .product-slider .item-product-slider .onsale' => 'width:{{SIZE}}{{UNIT}};height:{{SIZE}}{{UNIT}};',
],
]
);
$this->add_group_control(
Group_Control_Typography::get_type(),
[
'name' => 'sale_badge_typography',
'selector' => '{{WRAPPER}} .ova-product-slider .product-slider .item-product-slider .onsale',
]
);
$this->add_control(
'sale_badge_color',
[
'label' => esc_html__( 'Color', 'gimont' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .ova-product-slider .product-slider .item-product-slider .onsale' => 'color: {{VALUE}}',
],
]
);
$this->add_control(
'sale_badge_bgcolor',
[
'label' => esc_html__( 'Background Color', 'gimont' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .ova-product-slider .product-slider .item-product-slider .onsale' => 'background-color: {{VALUE}}',
],
]
);
$this->end_controls_section();
// Title
$this->start_controls_section(
'section_title_style',
[
'label' => esc_html__( 'Title', 'gimont' ),
'tab' => Controls_Manager::TAB_STYLE,
]
);
$this->add_group_control(
Group_Control_Typography::get_type(),
[
'name' => 'title_typography',
'selector' => '{{WRAPPER}} .ova-product-slider .product-slider .product-title',
]
);
$this->add_control(
'title_normal_color',
[
'label' => esc_html__( 'Color', 'gimont' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .ova-product-slider .product-slider .item-product-slider .product-title' => 'color: {{VALUE}}',
],
]
);
$this->add_control(
'title_hover_color',
[
'label' => esc_html__( 'Color Hover', 'gimont' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .ova-product-slider .product-slider .item-product-slider:hover .product-title' => 'color: {{VALUE}}',
],
]
);
$this->add_responsive_control(
'title_margin',
[
'label' => esc_html__( 'Margin', 'gimont' ),
'type' => Controls_Manager::DIMENSIONS,
'size_units' => [ 'px', '%', 'em' ],
'selectors' => [
'{{WRAPPER}} .ova-product-slider .product-slider .item-product-slider .product-title' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
],
]
);
$this->end_controls_section();
// Price
$this->start_controls_section(
'section_price_style',
[
'label' => esc_html__( 'Price', 'gimont' ),
'tab' => Controls_Manager::TAB_STYLE,
]
);
$this->add_group_control(
Group_Control_Typography::get_type(),
[
'name' => 'price_typography',
'selector' => '{{WRAPPER}} .ova-product-slider .product-slider .item-product-slider .woocommerce-Price-amount',
]
);
$this->add_control(
'price_color',
[
'label' => esc_html__( 'Color', 'gimont' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .ova-product-slider .product-slider .item-product-slider .woocommerce-Price-amount' => 'color: {{VALUE}}',
],
]
);
$this->add_control(
'price_color_hover',
[
'label' => esc_html__( 'Color Hover', 'gimont' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .ova-product-slider .product-slider .item-product-slider:hover .woocommerce-Price-amount' => 'color: {{VALUE}}',
],
]
);
$this->end_controls_section();
$this->start_controls_section(
'section_review_style',
[
'label' => esc_html__( 'Review', 'gimont' ),
'tab' => Controls_Manager::TAB_STYLE,
]
);
$this->add_control(
'star_color',
[
'label' => esc_html__( 'Star Color', 'gimont' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .ova-product-slider .product-slider .item-product-slider .star-rating' => 'color: {{VALUE}}',
],
]
);
$this->add_control(
'star_color_hover',
[
'label' => esc_html__( 'Star Color Hover', 'gimont' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .ova-product-slider .product-slider .item-product-slider:hover .star-rating' => 'color: {{VALUE}}',
],
]
);
$this->add_control(
'review_link_color',
[
'label' => esc_html__( 'Review Link Color', 'gimont' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .ova-product-slider .product-slider .item-product-slider .review-link' => 'color: {{VALUE}}',
],
]
);
$this->add_control(
'review_link_color_hover',
[
'label' => esc_html__( 'Review Link Color Hover', 'gimont' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .ova-product-slider .product-slider .item-product-slider:hover .review-link' => 'color: {{VALUE}}',
],
]
);
$this->end_controls_section();
/* Begin Nav Style */
$this->start_controls_section(
'nav_style',
[
'label' => esc_html__( 'Nav Control', 'gimont' ),
'tab' => Controls_Manager::TAB_STYLE,
'condition' => [
'nav_control' => 'yes',
]
]
);
$this->add_responsive_control(
'nav_icon_size',
[
'label' => esc_html__( 'Icon Size', 'gimont' ),
'type' => Controls_Manager::SLIDER,
'range' => [
'px' => [
'min' => 0,
'max' => 40,
],
],
'size_units' => [ 'px' ],
'selectors' => [
'{{WRAPPER}} .ova-product-slider .owl-carousel .owl-nav button i' => 'font-size: {{SIZE}}{{UNIT}};',
],
]
);
$this->add_responsive_control(
'nav_top_position',
[
'label' => esc_html__( 'Top Position', 'gimont' ),
'type' => Controls_Manager::SLIDER,
'range' => [
'px' => [
'min' => -150,
'max' => 450,
],
'%' => [
'min' => -150,
'max' => 150,
],
],
'size_units' => [ 'px', '%' ],
'selectors' => [
'{{WRAPPER}} .ova-product-slider .owl-carousel .owl-nav button' => 'top: {{SIZE}}{{UNIT}};',
],
]
);
$this->add_responsive_control(
'nav_right_position',
[
'label' => esc_html__( 'Right Position', 'gimont' ),
'type' => Controls_Manager::SLIDER,
'range' => [
'px' => [
'min' => 0,
'max' => 450,
],
'%' => [
'min' => 0,
'max' => 150,
],
],
'size_units' => [ 'px', '%' ],
'selectors' => [
'{{WRAPPER}} .ova-product-slider .owl-carousel .owl-nav button' => 'right: {{SIZE}}{{UNIT}};',
],
]
);
$this->start_controls_tabs( 'tabs_nav_style' );
$this->start_controls_tab(
'tab_nav_normal',
[
'label' => esc_html__( 'Normal', 'gimont' ),
]
);
$this->add_control(
'nav_color_normal',
[
'label' => esc_html__( 'Color', 'gimont' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .ova-product-slider .owl-carousel .owl-nav button i' => 'color: {{VALUE}}',
],
]
);
$this->add_control(
'nav_bgcolor_normal',
[
'label' => esc_html__( 'Background Color', 'gimont' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .ova-product-slider .owl-carousel .owl-nav button.owl-next, {{WRAPPER}} .ova-product-slider .owl-carousel .owl-nav button.owl-prev' => 'background-color: {{VALUE}}',
],
]
);
$this->end_controls_tab();
$this->start_controls_tab(
'tab_nav_hover',
[
'label' => esc_html__( 'Hover', 'gimont' ),
]
);
$this->add_control(
'nav_color_hover',
[
'label' => esc_html__( 'Color', 'gimont' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .ova-product-slider .owl-carousel .owl-nav button:hover i' => 'color: {{VALUE}}',
],
]
);
$this->add_control(
'nav_bgcolor_hover',
[
'label' => esc_html__( 'Background Color', 'gimont' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .ova-product-slider .owl-carousel .owl-nav button.owl-next:hover, {{WRAPPER}} .ova-product-slider .owl-carousel .owl-nav button.owl-prev:hover' => 'background-color: {{VALUE}}',
],
]
);
$this->end_controls_tab();
$this->end_controls_tabs();
$this->add_control(
'nav_border_radius',
[
'label' => esc_html__( 'Border Radius', 'gimont' ),
'type' => Controls_Manager::DIMENSIONS,
'size_units' => [ 'px', '%' ],
'selectors' => [
'{{WRAPPER}} .ova-product-slider .owl-carousel .owl-nav button' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
],
]
);
$this->end_controls_section();
/* End Nav Style */
/* Begin Dots Style */
$this->start_controls_section(
'dots_style',
[
'label' => esc_html__( 'Dots', 'gimont' ),
'tab' => Controls_Manager::TAB_STYLE,
'condition' => [
'dot_control' => 'yes',
]
]
);
$this->add_control(
'dots_margin',
[
'label' => esc_html__( 'Margin', 'gimont' ),
'type' => Controls_Manager::DIMENSIONS,
'size_units' => [ 'px', '%' ],
'selectors' => [
'{{WRAPPER}} .ova-product-slider .owl-dots' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
],
]
);
$this->start_controls_tabs( 'tabs_dots_style' );
$this->start_controls_tab(
'tab_dots_normal',
[
'label' => esc_html__( 'Normal', 'gimont' ),
]
);
$this->add_control(
'dot_color',
[
'label' => esc_html__( 'Color', 'gimont' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .ova-product-slider .owl-dots .owl-dot span' => 'background: {{VALUE}}',
],
]
);
$this->add_responsive_control(
'dots_width',
[
'label' => esc_html__( 'Width', 'gimont' ),
'type' => Controls_Manager::SLIDER,
'range' => [
'px' => [
'min' => 0,
'max' => 100,
],
],
'size_units' => [ 'px' ],
'selectors' => [
'{{WRAPPER}} .ova-product-slider .owl-dots .owl-dot span' => 'width: {{SIZE}}{{UNIT}};',
],
]
);
$this->add_responsive_control(
'dots_height',
[
'label' => esc_html__( 'Height', 'gimont' ),
'type' => Controls_Manager::SLIDER,
'range' => [
'px' => [
'min' => 0,
'max' => 100,
],
],
'size_units' => [ 'px' ],
'selectors' => [
'{{WRAPPER}} .ova-product-slider .owl-dots .owl-dot span' => 'height: {{SIZE}}{{UNIT}};',
],
]
);
$this->add_control(
'dots_border_radius',
[
'label' => esc_html__( 'Border Radius', 'gimont' ),
'type' => Controls_Manager::DIMENSIONS,
'size_units' => [ 'px', '%' ],
'selectors' => [
'{{WRAPPER}} .ova-product-slider .owl-dots .owl-dot span' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
],
]
);
$this->end_controls_tab();
$this->start_controls_tab(
'tab_dots_active',
[
'label' => esc_html__( 'Active', 'gimont' ),
]
);
$this->add_control(
'dot_color_active',
[
'label' => esc_html__( 'Color', 'gimont' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .ova-product-slider .owl-dots .owl-dot.active span' => 'background: {{VALUE}}',
'{{WRAPPER}} .ova-product-slider .owl-dots .owl-dot span:before' => 'border-color: {{VALUE}}',
],
]
);
$this->add_responsive_control(
'dots_width_active',
[
'label' => esc_html__( 'Width', 'gimont' ),
'type' => Controls_Manager::SLIDER,
'range' => [
'px' => [
'min' => 0,
'max' => 100,
],
],
'size_units' => [ 'px' ],
'selectors' => [
'{{WRAPPER}} .ova-product-slider .owl-dots .owl-dot.active span' => 'width: {{SIZE}}{{UNIT}};',
],
]
);
$this->add_responsive_control(
'dots_height_active',
[
'label' => esc_html__( 'Height', 'gimont' ),
'type' => Controls_Manager::SLIDER,
'range' => [
'px' => [
'min' => 0,
'max' => 100,
],
],
'size_units' => [ 'px' ],
'selectors' => [
'{{WRAPPER}} .ova-product-slider .owl-dots .owl-dot.active span' => 'height: {{SIZE}}{{UNIT}};',
],
]
);
$this->add_control(
'dots_border_radius_active',
[
'label' => esc_html__( 'Border Radius', 'gimont' ),
'type' => Controls_Manager::DIMENSIONS,
'size_units' => [ 'px', '%' ],
'selectors' => [
'{{WRAPPER}} .ova-product-slider .owl-dots .owl-dot.active span' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
],
]
);
$this->end_controls_tab();
$this->end_controls_tabs();
$this->end_controls_section();
/* End Dots Style */
}
protected function gimont_get_product_slider( $args ) {
$args_query = [
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => $args['posts_per_page'],
'orderby' => $args['orderby'],
'order' => $args['order'],
'tax_query' => [],
];
if ( 'yes' === $args['show_featured'] ) {
$featured = [
'taxonomy' => 'product_visibility',
'field' => 'name',
'terms' => 'featured',
'operator' => 'IN'
];
array_push( $args_query['tax_query'], $featured );
}
if ( 'all' != $args['category_slug'] ) {
$category_args = [
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => $args['category_slug'],
'operator' => 'IN',
];
array_push( $args_query['tax_query'], $category_args );
}
if ( $args['category_in'] ) {
$category_in = [
[
'taxonomy' => 'product_cat',
'field' => 'term_id',
'terms' => explode( '|', $args['category_in'] ),
'operator' => 'IN',
],
];
array_push( $args_query['tax_query'], $category_in );
}
if ( $args['category_not_in'] ) {
$category_not_in = [
[
'taxonomy' => 'product_cat',
'field' => 'term_id',
'terms' => explode( '|', $args['category_not_in'] ),
'operator' => 'NOT IN',
],
];
array_push( $args_query['tax_query'], $category_not_in );
}
$result = new \WP_Query( $args_query );
return $result;
}
protected function render() {
$settings = $this->get_settings();
$limit = $settings['limit'];
$short_des_limit = $settings['short_des_limit'];
$show_review = $settings['show_review'];
$show_short_des = $settings['show_short_des'];
$show_link_to_detail = $settings['show_link_to_detail'];
$args = [
'posts_per_page' => $settings['posts_per_page'],
'orderby' => $settings['orderby'],
'order' => $settings['order'],
'category_slug' => $settings['categories'],
'category_in' => $settings['category_in'],
'category_not_in' => $settings['category_not_in'],
'show_featured' => $settings['show_featured']
];
// carousel data option
$data_options['items'] = $settings['item_number'];
$data_options['slideBy'] = $settings['slides_to_scroll'];
$data_options['margin'] = $settings['margin_items'];
$data_options['autoplayHoverPause'] = $settings['pause_on_hover'] === 'yes' ? true : false;
$data_options['loop'] = $settings['infinite'] === 'yes' ? true : false;
$data_options['autoplay'] = $settings['autoplay'] === 'yes' ? true : false;
$data_options['autoplay_speed'] = $settings['autoplay_speed'] ? $settings['autoplay_speed'] : '3000';
$data_options['smartSpeed'] = $settings['smartspeed'] ? $settings['smartspeed'] : '500';
$data_options['dots'] = $settings['dot_control'] === 'yes' ? true : false;
$data_options['nav'] = $settings['nav_control'] === 'yes' ? true : false;
$data_options['rtl'] = is_rtl() ? true: false;
$products = $this->gimont_get_product_slider( $args );
?>
<?php if ( $products->have_posts() ): ?>
<div class="ova-product-slider">
<div class="product-slider owl-carousel owl-theme" data-options="<?php echo esc_attr(json_encode($data_options)) ?>">
<?php while( $products->have_posts() ) : $products->the_post();
$id = get_the_ID();
$product = wc_get_product( $id );
$title = wp_trim_words(get_the_title(),$limit,'');
$img_url = get_the_post_thumbnail_url($id, 'medium');
$img_alt = get_post_meta( $id , '_wp_attachment_image_alt', true ) ? get_post_meta( $id , '_wp_attachment_image_alt', true ) : $title;
if( $img_url == '') {
$img_url = wc_placeholder_img_src( 'medium' );
}
$rating = $product->get_average_rating();
$count = $product->get_rating_count();
$permarlink = $product->get_permalink();
$sale_price = $product->get_sale_price();
$short_des = $product->get_short_description();
$short_des = wp_trim_words($short_des, $short_des_limit,'');
$sale_html = apply_filters( 'woocommerce_sale_flash', '', $product, $product );
$add_to_cart_url = wc_get_cart_url().$product->add_to_cart_url();
?>
<div class="item-product-slider">
<div class="product-image">
<img src="<?php echo esc_url($img_url);?>" alt="<?php echo esc_attr($img_alt);?>">
</div>
<?php if( $sale_price != '' ) {
echo apply_filters('the_content',$sale_html);
} ?>
<div class="product-content">
<?php if($show_review == 'yes' && !empty($rating)) { ?>
<div class="product-rating">
<?php echo wc_get_rating_html( $rating ); ?>
</div>
<?php } ?>
<?php if($show_link_to_detail == 'yes') : ?>
<a href="<?php echo esc_url($permarlink);?>" class="element-product-link">
<?php endif;?>
<h2 class="product-title">
<?php echo esc_html($title);?>
</h2>
<?php if($show_link_to_detail == 'yes') : ?>
</a>
<?php endif;?>
<?php if( $show_short_des == 'yes' && $short_des != '' ) { ?>
<p class="product-short-description">
<?php echo esc_html($short_des); ?>
</p>
<?php } ?>
</div>
<?php echo do_shortcode( '[add_to_cart id='.$id.' style="border:none;margin:0;"]' ); ?>
</div>
<?php endwhile; ?>
</div>
</div>
<?php else: ?>
<div class="ova-no-products-found">
<?php echo esc_html__( 'No products found', 'gimont' ); ?>
</div>
<?php endif; wp_reset_postdata(); ?>
<?php
}
}
$widgets_manager->register( new Gimont_Elementor_Product_Slider() );