PluginProbe
King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder / 51.1.63
King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder v51.1.63
51.1.86 51.1.84 51.1.85 51.1.83 51.1.82 51.1.81 51.1.79 51.1.78 51.1.77 51.1.76 51.1.74 51.1.75 51.1.65 51.1.64 51.1.63 trunk 51.1.14 51.1.2 51.1.35 51.1.36 51.1.37 51.1.38 51.1.39 51.1.44 51.1.45 All 40 releases
king-addons / includes / widgets / Woo_Product_Countdown / Woo_Product_Countdown.php

Woo_Product_Countdown.php in King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder 51.1.63, at includes/widgets/Woo_Product_Countdown/Woo_Product_Countdown.php

257 lines 9.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Woo Product Countdown widget.
4 *
5 * @package King_Addons
6 */
7
8 namespace King_Addons;
9
10 use Elementor\Controls_Manager;
11 use Elementor\Group_Control_Typography;
12
13 if (!defined('ABSPATH')) {
14 exit;
15 }
16
17 /**
18 * Displays countdown until sale ends.
19 */
20 class Woo_Product_Countdown extends Abstract_Single_Widget
21 {
22 public function get_name(): string
23 {
24 return 'woo_product_countdown';
25 }
26
27 public function get_title(): string
28 {
29 return esc_html__('Product Sale Countdown', 'king-addons');
30 }
31
32 public function get_icon(): string
33 {
34 return 'eicon-countdown';
35 }
36
37 public function get_categories(): array
38 {
39 return ['king-addons-woo-builder'];
40 }
41
42 public function get_style_depends(): array
43 {
44 return [KING_ADDONS_ASSETS_UNIQUE_KEY . '-woo-product-countdown-style'];
45 }
46
47 public function get_script_depends(): array
48 {
49 return [KING_ADDONS_ASSETS_UNIQUE_KEY . '-woo-product-countdown-script'];
50 }
51
52 protected function register_controls(): void
53 {
54 $this->start_controls_section(
55 'section_content',
56 [
57 'label' => esc_html__('Content', 'king-addons'),
58 'tab' => Controls_Manager::TAB_CONTENT,
59 ]
60 );
61
62 $this->add_control(
63 'custom_date',
64 [
65 'label' => sprintf(__('Custom end date %s', 'king-addons'), '<i class="eicon-pro-icon"></i>'),
66 'type' => Controls_Manager::DATE_TIME,
67 ]
68 );
69
70 $this->add_control(
71 'display_format',
72 [
73 'label' => sprintf(__('Display format %s', 'king-addons'), '<i class="eicon-pro-icon"></i>'),
74 'type' => Controls_Manager::SELECT,
75 'options' => [
76 'blocks' => esc_html__('Blocks', 'king-addons'),
77 'inline' => esc_html__('Inline (Pro)', 'king-addons'),
78 ],
79 'default' => 'blocks',
80 ]
81 );
82
83 $this->add_control(
84 'show_seconds',
85 [
86 'label' => sprintf(__('Show seconds %s', 'king-addons'), '<i class="eicon-pro-icon"></i>'),
87 'type' => Controls_Manager::SWITCHER,
88 'return_value' => 'yes',
89 ]
90 );
91
92 $this->add_control(
93 'expired_behavior',
94 [
95 'label' => sprintf(__('After expire %s', 'king-addons'), '<i class="eicon-pro-icon"></i>'),
96 'type' => Controls_Manager::SELECT,
97 'options' => [
98 'hide' => esc_html__('Hide', 'king-addons'),
99 'text' => esc_html__('Show text', 'king-addons'),
100 'zero' => esc_html__('Freeze at 0', 'king-addons'),
101 ],
102 'default' => 'hide',
103 ]
104 );
105
106 $this->add_control(
107 'expired_text',
108 [
109 'label' => esc_html__('Expired text (Pro)', 'king-addons'),
110 'type' => Controls_Manager::TEXT,
111 'default' => esc_html__('Offer ended', 'king-addons'),
112 ]
113 );
114
115 $this->end_controls_section();
116
117 $this->start_controls_section(
118 'section_style',
119 [
120 'label' => esc_html__('Style', 'king-addons'),
121 'tab' => Controls_Manager::TAB_STYLE,
122 ]
123 );
124
125 $this->add_group_control(
126 Group_Control_Typography::get_type(),
127 [
128 'name' => 'numbers_typo',
129 'selector' => '{{WRAPPER}} .ka-woo-countdown__number',
130 'label' => esc_html__('Numbers Typography', 'king-addons'),
131 ]
132 );
133
134 $this->add_control(
135 'numbers_color',
136 [
137 'label' => esc_html__('Numbers Color', 'king-addons'),
138 'type' => Controls_Manager::COLOR,
139 'selectors' => [
140 '{{WRAPPER}} .ka-woo-countdown__number' => 'color: {{VALUE}};',
141 ],
142 ]
143 );
144
145 $this->add_group_control(
146 Group_Control_Typography::get_type(),
147 [
148 'name' => 'labels_typo',
149 'selector' => '{{WRAPPER}} .ka-woo-countdown__label',
150 'label' => esc_html__('Labels Typography', 'king-addons'),
151 ]
152 );
153
154 $this->add_control(
155 'labels_color',
156 [
157 'label' => esc_html__('Labels Color', 'king-addons'),
158 'type' => Controls_Manager::COLOR,
159 'selectors' => [
160 '{{WRAPPER}} .ka-woo-countdown__label' => 'color: {{VALUE}};',
161 ],
162 ]
163 );
164
165 $this->add_responsive_control(
166 'gap',
167 [
168 'label' => esc_html__('Items Gap', 'king-addons'),
169 'type' => Controls_Manager::SLIDER,
170 'range' => [
171 'px' => ['min' => 0, 'max' => 40],
172 ],
173 'selectors' => [
174 '{{WRAPPER}} .ka-woo-countdown' => 'gap: {{SIZE}}{{UNIT}};',
175 ],
176 ]
177 );
178
179 $this->end_controls_section();
180 }
181
182 protected function render(): void
183 {
184 $product = $this->get_product();
185 if (!$product) {
186 $this->render_missing_product_notice();
187 return;
188 }
189
190 $settings = $this->get_settings_for_display();
191 $can_pro = king_addons_can_use_pro();
192
193 $format = $settings['display_format'] ?? 'blocks';
194 if ('inline' === $format && !$can_pro) {
195 $format = 'blocks';
196 }
197
198 $end_timestamp = 0;
199 $custom_date = $settings['custom_date'] ?? '';
200 if (!empty($custom_date) && $can_pro) {
201 $end_timestamp = strtotime($custom_date);
202 }
203
204 if (!$end_timestamp) {
205 $end_timestamp = (int) get_post_meta($product->get_id(), '_sale_price_dates_to', true);
206 }
207
208 if (!$end_timestamp || $end_timestamp <= time()) {
209 $behavior = $settings['expired_behavior'] ?? 'hide';
210 if (!empty($settings['expired_text']) && 'text' === $behavior && $can_pro) {
211 echo '<div class="ka-woo-countdown ka-woo-countdown--expired">' . esc_html($settings['expired_text']) . '</div>';
212 } elseif ('zero' === $behavior) {
213 echo '<div class="ka-woo-countdown ka-woo-countdown--expired"><div class="ka-woo-countdown__item"><span class="ka-woo-countdown__number">0</span><span class="ka-woo-countdown__label">' . esc_html__('Time', 'king-addons') . '</span></div></div>';
214 }
215 return;
216 }
217
218 $show_seconds = !empty($settings['show_seconds']) && $can_pro;
219
220 $behavior = $settings['expired_behavior'] ?? 'hide';
221 $expired_text = (!empty($settings['expired_text']) && $can_pro) ? $settings['expired_text'] : '';
222
223 $classes = ['ka-woo-countdown', 'ka-woo-countdown--' . $format];
224
225 echo '<div class="' . esc_attr(implode(' ', $classes)) . '" data-end="' . esc_attr((string) $end_timestamp) . '" data-seconds="' . ($show_seconds ? 'yes' : 'no') . '" data-expire="' . esc_attr($behavior) . '" data-expire-text="' . esc_attr($expired_text) . '">';
226
227 if ('inline' === $format) {
228 echo '<div class="ka-woo-countdown__inline">';
229 echo '<span class="ka-woo-countdown__number" data-unit="days">0</span><span class="ka-woo-countdown__label">d</span>';
230 echo '<span class="ka-woo-countdown__sep">:</span>';
231 echo '<span class="ka-woo-countdown__number" data-unit="hours">00</span><span class="ka-woo-countdown__label">h</span>';
232 echo '<span class="ka-woo-countdown__sep">:</span>';
233 echo '<span class="ka-woo-countdown__number" data-unit="minutes">00</span><span class="ka-woo-countdown__label">m</span>';
234 if ($show_seconds) {
235 echo '<span class="ka-woo-countdown__sep">:</span>';
236 echo '<span class="ka-woo-countdown__number" data-unit="seconds">00</span><span class="ka-woo-countdown__label">s</span>';
237 }
238 echo '</div>';
239 } else {
240 echo '<div class="ka-woo-countdown__item"><span class="ka-woo-countdown__number" data-unit="days">0</span><span class="ka-woo-countdown__label">' . esc_html__('Days', 'king-addons') . '</span></div>';
241 echo '<div class="ka-woo-countdown__item"><span class="ka-woo-countdown__number" data-unit="hours">0</span><span class="ka-woo-countdown__label">' . esc_html__('Hours', 'king-addons') . '</span></div>';
242 echo '<div class="ka-woo-countdown__item"><span class="ka-woo-countdown__number" data-unit="minutes">0</span><span class="ka-woo-countdown__label">' . esc_html__('Minutes', 'king-addons') . '</span></div>';
243 if ($show_seconds) {
244 echo '<div class="ka-woo-countdown__item"><span class="ka-woo-countdown__number" data-unit="seconds">0</span><span class="ka-woo-countdown__label">' . esc_html__('Seconds', 'king-addons') . '</span></div>';
245 }
246 }
247 echo '</div>';
248 }
249 }
250
251
252
253
254
255
256
257