File: /mnt/data/truelysell-wp-demo/wp-content/plugins/truelysell-elementor/widgets/class-counter.php
<?php
namespace ElementorTruelysell\Widgets;
use Elementor\Widget_Base;
use Elementor\Controls_Manager;
use Elementor\Group_Control_Typography;
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
class Facts_Counter extends Widget_Base {
public function get_name() {
return 'facts-counter';
}
public function get_title() {
return __( 'Truelysell Counter', 'truelysell-elementor' );
}
public function get_icon() {
return 'eicon-counter-circle';
}
public function get_categories() {
return [ 'truelysell' ];
}
public function get_script_depends() {
return [ '' ];
}
/**
* Register the widget controls.
*
* Adds different input fields to allow the user to change and customize the widget settings.
*
* @since 1.0.0
*
* @access protected
*/
protected function register_controls() {
$this->start_controls_section(
'section_query',
[
'label' => esc_html__( 'Facts Counter', 'truelysell-elementor' ),
]
);
$this->add_control(
'style',
[
'label' => __( 'Style ', 'truelysell_elementor' ),
'type' => \Elementor\Controls_Manager::SELECT,
'default' => 'style1',
'options' => [
'style1' => __( 'Style 1', 'truelysell_elementor' ),
'style2' => __( 'Style 2', 'truelysell_elementor' ),
],
]
);
$this->add_control(
'stitle', [
'label' => __( 'Sub-Title', 'truelysell-elementor' ),
'type' => \Elementor\Controls_Manager::TEXT,
'label_block' => true,
'condition' => [
'style' => [ 'style2'],
],
]
);
$this->add_control(
'title', [
'label' => __( 'Title', 'truelysell-elementor' ),
'type' => \Elementor\Controls_Manager::TEXT,
'label_block' => true,
'condition' => [
'style' => [ 'style2'],
],
]
);
$this->add_control(
'background',
[
'label' => __( 'Image', 'dreamslms_elementor' ),
'type' => \Elementor\Controls_Manager::MEDIA,
'condition' => [
'style' => [ 'style1'],
],
]
);
$this->add_control(
'background2',
[
'label' => __( 'Background', 'dreamslms_elementor' ),
'type' => \Elementor\Controls_Manager::MEDIA,
'condition' => [
'style' => [ 'style1'],
],
]
);
$repeater = new \Elementor\Repeater();
$repeater->add_control(
'counter_title', [
'label' => __( 'Counter Title', 'truelysell-elementor' ),
'type' => \Elementor\Controls_Manager::TEXT,
'label_block' => true,
]
);
$repeater->add_control(
'counter_numbers',
[
'label' => __( 'Value in Digits', 'truelysell-elementor' ),
'type' => \Elementor\Controls_Manager::NUMBER,
'label_block' => true,
]
);
$this->add_control(
'counter_list',
[
'label' => __( 'Counters', 'truelysell-elementor' ),
'type' => \Elementor\Controls_Manager::REPEATER,
'fields' => $repeater->get_controls(),
]
);
$this->end_controls_section();
// Style: Counter Numbers
$this->start_controls_section(
'counter_numbers_style',
[
'label' => __( 'Counter Numbers', 'truelysell-elementor' ),
'tab' => Controls_Manager::TAB_STYLE,
]
);
$this->add_control(
'counter_numbers_color',
[
'label' => __( 'Number Color', 'truelysell-elementor' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .clients-eights-all h3.counter' => 'color: {{VALUE}};',
'{{WRAPPER}} .journey-client-counter h2.counter' => 'color: {{VALUE}};',
],
]
);
$this->add_group_control(
Group_Control_Typography::get_type(),
[
'name' => 'counter_numbers_typography',
'label' => __( 'Typography', 'truelysell-elementor' ),
'selector' => '{{WRAPPER}} .clients-eights-all h3.counter, {{WRAPPER}} .journey-client-counter h2.counter',
]
);
$this->end_controls_section();
// Style: Counter Labels
$this->start_controls_section(
'counter_labels_style',
[
'label' => __( 'Counter Labels', 'truelysell-elementor' ),
'tab' => Controls_Manager::TAB_STYLE,
]
);
$this->add_control(
'counter_labels_color',
[
'label' => __( 'Label Color', 'truelysell-elementor' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .clients-eights-all p' => 'color: {{VALUE}};',
'{{WRAPPER}} .journey-client-main h5' => 'color: {{VALUE}};',
],
]
);
$this->add_group_control(
Group_Control_Typography::get_type(),
[
'name' => 'counter_labels_typography',
'label' => __( 'Typography', 'truelysell-elementor' ),
'selector' => '{{WRAPPER}} .clients-eights-all p, {{WRAPPER}} .journey-client-main h5',
]
);
$this->end_controls_section();
// Style: Section Heading (Style 2)
$this->start_controls_section(
'counter_section_heading_style',
[
'label' => __( 'Section Heading', 'truelysell-elementor' ),
'tab' => Controls_Manager::TAB_STYLE,
]
);
$this->add_control(
'counter_section_heading_title_color',
[
'label' => __( 'Title Color', 'truelysell-elementor' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .journey-heading-nine h2' => 'color: {{VALUE}};',
],
]
);
$this->add_group_control(
Group_Control_Typography::get_type(),
[
'name' => 'counter_section_heading_title_typography',
'label' => __( 'Title Typography', 'truelysell-elementor' ),
'selector' => '{{WRAPPER}} .journey-heading-nine h2',
]
);
$this->add_control(
'counter_section_heading_subtitle_color',
[
'label' => __( 'Subtitle Color', 'truelysell-elementor' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .journey-heading-nine p' => 'color: {{VALUE}};',
],
]
);
$this->add_group_control(
Group_Control_Typography::get_type(),
[
'name' => 'counter_section_heading_subtitle_typography',
'label' => __( 'Subtitle Typography', 'truelysell-elementor' ),
'selector' => '{{WRAPPER}} .journey-heading-nine p',
]
);
$this->end_controls_section();
}
protected function render() {
$settings = $this->get_settings_for_display();
$params['counter_list'] = $settings['counter_list'];
$counter_lists = $params[ 'counter_list' ];
?>
<?php if($settings['style']=='style1'){ ?>
<div class="row">
<div class="col-lg-6 col-12">
<div class="row">
<?php foreach ( $counter_lists as $counter_list ) { ?>
<div class="col-lg-6 col-md-6 col-12">
<div class="clients-eights-all">
<div class="clients-eight-span">
<h3 class="counter animated fadeInDownBig"><?php echo $counter_list[ 'counter_numbers' ];?></h3>
<span>+</span>
</div>
<p><?php echo $counter_list[ 'counter_title' ];?></p>
</div>
</div>
<?php } ?>
</div>
</div>
<div class="col-lg-6 col-12">
<div class="professional-eight-img">
<img src="<?php echo $settings['background']['url']; ?>" alt="" class="img-fluid">
<div class="professional-eight-bg">
<img src="<?php echo $settings['background2']['url']; ?>" alt="">
</div>
</div>
</div>
</div>
<?php } else if($settings['style']=='style2'){ ?>
<div class="container">
<div class="row">
<div class="col-lg-4">
<div class="section-heading section-heading-nine journey-heading-nine aos" data-aos="fade-up">
<p><?php echo $settings['stitle']; ?></p>
<h2><?php echo $settings['title']; ?></h2>
</div>
</div>
<?php foreach ( $counter_lists as $counter_list ) { ?>
<div class="col-lg-2 d-flex justify-content-center align-items-center">
<div class="journey-client-all aos" data-aos="fade-up">
<div class="journey-client-main">
<div class="journey-client-counter">
<h2 class="counter"><?php echo $counter_list[ 'counter_numbers' ];?></h2>
<span>+</span>
</div>
<h5><?php echo $counter_list[ 'counter_title' ];?></h5>
</div>
</div>
</div>
<?php } ?>
</div>
</div>
<?php } ?>
<?php }
}