PluginProbe
King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder / 51.1.49
King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder v51.1.49
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 51.1.46 51.1.47 51.1.49 All 37 releases
king-addons / includes / widgets / Pricing_Table_Ext / Pricing_Table_Ext.php

Pricing_Table_Ext.php in King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder 51.1.49, at includes/widgets/Pricing_Table_Ext/Pricing_Table_Ext.php

421 lines 12.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Pricing Table Extension Widget for Elementor.
4 *
5 * Displays pricing tables created with the Pricing Table Builder.
6 *
7 * @package King_Addons
8 */
9
10 namespace King_Addons;
11
12 use Elementor\Widget_Base;
13 use Elementor\Controls_Manager;
14
15 if (!defined('ABSPATH')) {
16 exit;
17 }
18
19 /**
20 * Pricing Table Extension Widget.
21 */
22 class Pricing_Table_Ext extends Widget_Base
23 {
24 /**
25 * Get widget name.
26 *
27 * @return string
28 */
29 public function get_name(): string
30 {
31 return 'king-addons-pricing-table-ext';
32 }
33
34 /**
35 * Get widget title.
36 *
37 * @return string
38 */
39 public function get_title(): string
40 {
41 return esc_html__('Pricing Table', 'king-addons');
42 }
43
44 /**
45 * Get widget icon.
46 *
47 * @return string
48 */
49 public function get_icon(): string
50 {
51 return 'king-addons-icon king-addons-pricing-table-ext';
52 }
53
54 /**
55 * Get widget categories.
56 *
57 * @return array
58 */
59 public function get_categories(): array
60 {
61 return ['king-addons'];
62 }
63
64 /**
65 * Get widget keywords.
66 *
67 * @return array
68 */
69 public function get_keywords(): array
70 {
71 return ['pricing', 'table', 'plans', 'price', 'comparison', 'subscription', 'billing'];
72 }
73
74 /**
75 * Get style dependencies.
76 *
77 * @return array
78 */
79 public function get_style_depends(): array
80 {
81 return ['king-addons-pt-frontend'];
82 }
83
84 /**
85 * Get script dependencies.
86 *
87 * @return array
88 */
89 public function get_script_depends(): array
90 {
91 return ['king-addons-pt-frontend'];
92 }
93
94 /**
95 * Register widget controls.
96 *
97 * @return void
98 */
99 protected function register_controls(): void
100 {
101 // Content Section - Source
102 $this->start_controls_section(
103 'section_source',
104 [
105 'label' => esc_html__('Source', 'king-addons'),
106 'tab' => Controls_Manager::TAB_CONTENT,
107 ]
108 );
109
110 $this->add_control(
111 'table_id',
112 [
113 'label' => esc_html__('Select Pricing Table', 'king-addons'),
114 'type' => Controls_Manager::SELECT2,
115 'options' => $this->get_pricing_tables(),
116 'default' => '',
117 'label_block' => true,
118 'description' => sprintf(
119 '%s <a href="%s" target="_blank">%s</a>',
120 esc_html__('Select a pricing table or', 'king-addons'),
121 admin_url('admin.php?page=king-addons-pricing-tables&action=new'),
122 esc_html__('create a new one', 'king-addons')
123 ),
124 ]
125 );
126
127 $this->end_controls_section();
128
129 // Content Section - Display Options
130 $this->start_controls_section(
131 'section_display',
132 [
133 'label' => esc_html__('Display', 'king-addons'),
134 'tab' => Controls_Manager::TAB_CONTENT,
135 ]
136 );
137
138 $this->add_control(
139 'hide_toggle',
140 [
141 'label' => esc_html__('Hide Billing Toggle', 'king-addons'),
142 'type' => Controls_Manager::SWITCHER,
143 'default' => '',
144 'description' => esc_html__('Hide the monthly/annual toggle', 'king-addons'),
145 ]
146 );
147
148 $this->add_control(
149 'force_period',
150 [
151 'label' => esc_html__('Force Period', 'king-addons'),
152 'type' => Controls_Manager::SELECT,
153 'options' => [
154 '' => esc_html__('Default', 'king-addons'),
155 'monthly' => esc_html__('Monthly', 'king-addons'),
156 'annual' => esc_html__('Annual', 'king-addons'),
157 ],
158 'default' => '',
159 'description' => esc_html__('Force a specific billing period', 'king-addons'),
160 ]
161 );
162
163 $this->end_controls_section();
164
165 // Style Section - Layout
166 $this->start_controls_section(
167 'section_style_layout',
168 [
169 'label' => esc_html__('Layout', 'king-addons'),
170 'tab' => Controls_Manager::TAB_STYLE,
171 ]
172 );
173
174 $this->add_responsive_control(
175 'columns',
176 [
177 'label' => esc_html__('Columns', 'king-addons'),
178 'type' => Controls_Manager::SELECT,
179 'options' => [
180 '' => esc_html__('Default', 'king-addons'),
181 '1' => '1',
182 '2' => '2',
183 '3' => '3',
184 '4' => '4',
185 '5' => '5',
186 '6' => '6',
187 ],
188 'default' => '',
189 'tablet_default' => '',
190 'mobile_default' => '',
191 ]
192 );
193
194 $this->add_control(
195 'max_width',
196 [
197 'label' => esc_html__('Max Width', 'king-addons'),
198 'type' => Controls_Manager::SLIDER,
199 'size_units' => ['px', '%'],
200 'range' => [
201 'px' => [
202 'min' => 600,
203 'max' => 2000,
204 'step' => 10,
205 ],
206 '%' => [
207 'min' => 50,
208 'max' => 100,
209 ],
210 ],
211 'default' => [
212 'unit' => 'px',
213 'size' => '',
214 ],
215 ]
216 );
217
218 $this->add_responsive_control(
219 'alignment',
220 [
221 'label' => esc_html__('Alignment', 'king-addons'),
222 'type' => Controls_Manager::CHOOSE,
223 'options' => [
224 'left' => [
225 'title' => esc_html__('Left', 'king-addons'),
226 'icon' => 'eicon-text-align-left',
227 ],
228 'center' => [
229 'title' => esc_html__('Center', 'king-addons'),
230 'icon' => 'eicon-text-align-center',
231 ],
232 'right' => [
233 'title' => esc_html__('Right', 'king-addons'),
234 'icon' => 'eicon-text-align-right',
235 ],
236 ],
237 'default' => '',
238 ]
239 );
240
241 $this->end_controls_section();
242
243 // Style Section - Colors (Pro)
244 $this->start_controls_section(
245 'section_style_colors',
246 [
247 'label' => esc_html__('Colors', 'king-addons'),
248 'tab' => Controls_Manager::TAB_STYLE,
249 ]
250 );
251
252 $is_premium = function_exists('king_addons_freemius') && king_addons_freemius()->can_use_premium_code__premium_only();
253
254 if ($is_premium) {
255 $this->add_control(
256 'color_accent',
257 [
258 'label' => esc_html__('Accent Color', 'king-addons'),
259 'type' => Controls_Manager::COLOR,
260 'default' => '',
261 'selectors' => [
262 '{{WRAPPER}} .kng-pt-wrapper' => '--kng-pt-accent: {{VALUE}};',
263 ],
264 ]
265 );
266
267 $this->add_control(
268 'color_card_bg',
269 [
270 'label' => esc_html__('Card Background', 'king-addons'),
271 'type' => Controls_Manager::COLOR,
272 'default' => '',
273 'selectors' => [
274 '{{WRAPPER}} .kng-pt-wrapper' => '--kng-pt-card-bg: {{VALUE}};',
275 ],
276 ]
277 );
278
279 $this->add_control(
280 'color_text',
281 [
282 'label' => esc_html__('Text Color', 'king-addons'),
283 'type' => Controls_Manager::COLOR,
284 'default' => '',
285 'selectors' => [
286 '{{WRAPPER}} .kng-pt-wrapper' => '--kng-pt-text: {{VALUE}};',
287 ],
288 ]
289 );
290
291 $this->add_control(
292 'color_muted',
293 [
294 'label' => esc_html__('Muted Text Color', 'king-addons'),
295 'type' => Controls_Manager::COLOR,
296 'default' => '',
297 'selectors' => [
298 '{{WRAPPER}} .kng-pt-wrapper' => '--kng-pt-muted: {{VALUE}};',
299 ],
300 ]
301 );
302 } else {
303 $this->add_control(
304 'colors_pro_notice',
305 [
306 'type' => Controls_Manager::RAW_HTML,
307 'raw' => sprintf(
308 '<div style="padding: 15px; background: #f0f0f1; border-radius: 4px;">
309 <strong>%s</strong><br>%s <a href="%s" target="_blank">%s</a>
310 </div>',
311 esc_html__('Pro Feature', 'king-addons'),
312 esc_html__('Color overrides are available in the Pro version.', 'king-addons'),
313 'https://kingaddons.com/pricing/',
314 esc_html__('Upgrade Now', 'king-addons')
315 ),
316 ]
317 );
318 }
319
320 $this->end_controls_section();
321 }
322
323 /**
324 * Get pricing tables for select control.
325 *
326 * @return array
327 */
328 private function get_pricing_tables(): array
329 {
330 $tables = get_posts([
331 'post_type' => Pricing_Table_Builder::POST_TYPE,
332 'posts_per_page' => -1,
333 'post_status' => 'publish',
334 'orderby' => 'title',
335 'order' => 'ASC',
336 ]);
337
338 $options = ['' => esc_html__('Select a table', 'king-addons')];
339
340 foreach ($tables as $table) {
341 $options[$table->ID] = $table->post_title;
342 }
343
344 return $options;
345 }
346
347 /**
348 * Render widget output.
349 *
350 * @return void
351 */
352 protected function render(): void
353 {
354 $settings = $this->get_settings_for_display();
355 $table_id = (int)($settings['table_id'] ?? 0);
356
357 if (!$table_id) {
358 if (\Elementor\Plugin::$instance->editor->is_edit_mode()) {
359 echo '<div style="padding: 40px; text-align: center; background: #f5f5f7; border-radius: 12px;">';
360 echo '<p style="color: #86868b; margin: 0;">' . esc_html__('Please select a pricing table from the widget settings.', 'king-addons') . '</p>';
361 echo '</div>';
362 }
363 return;
364 }
365
366 $builder = Pricing_Table_Builder::instance();
367
368 $overrides = [];
369
370 if (!empty($settings['hide_toggle'])) {
371 $overrides['hide_toggle'] = true;
372 }
373
374 if (!empty($settings['force_period'])) {
375 $overrides['force_period'] = $settings['force_period'];
376 }
377
378 // Responsive columns
379 if (!empty($settings['columns'])) {
380 $overrides['columns_desktop'] = $settings['columns'];
381 }
382 if (!empty($settings['columns_tablet'])) {
383 $overrides['columns_tablet'] = $settings['columns_tablet'];
384 }
385 if (!empty($settings['columns_mobile'])) {
386 $overrides['columns_mobile'] = $settings['columns_mobile'];
387 }
388
389 if (!empty($settings['max_width']['size'])) {
390 $overrides['max_width'] = $settings['max_width']['size'];
391 }
392
393 if (!empty($settings['alignment'])) {
394 $overrides['alignment'] = $settings['alignment'];
395 }
396
397 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
398 echo $builder->render_for_elementor($table_id, $overrides);
399 }
400
401 /**
402 * Render widget output in the editor.
403 *
404 * @return void
405 */
406 protected function content_template(): void
407 {
408 ?>
409 <#
410 if (!settings.table_id) {
411 #>
412 <div style="padding: 40px; text-align: center; background: #f5f5f7; border-radius: 12px;">
413 <p style="color: #86868b; margin: 0;"><?php echo esc_html__('Please select a pricing table from the widget settings.', 'king-addons'); ?></p>
414 </div>
415 <#
416 }
417 #>
418 <?php
419 }
420 }
421