PluginProbe
King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder / 51.1.83
King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder v51.1.83
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.83, at includes/widgets/Pricing_Table_Ext/Pricing_Table_Ext.php

426 lines 12.4 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 public function get_custom_help_url()
95 {
96 return 'mailto:bug@kingaddons.com?subject=Bug Report - King Addons&body=Please describe the issue';
97 }
98
99 /**
100 * Register widget controls.
101 *
102 * @return void
103 */
104 protected function register_controls(): void
105 {
106 // Content Section - Source
107 $this->start_controls_section(
108 'section_source',
109 [
110 'label' => esc_html__('Source', 'king-addons'),
111 'tab' => Controls_Manager::TAB_CONTENT,
112 ]
113 );
114
115 $this->add_control(
116 'table_id',
117 [
118 'label' => esc_html__('Select Pricing Table', 'king-addons'),
119 'type' => Controls_Manager::SELECT2,
120 'options' => $this->get_pricing_tables(),
121 'default' => '',
122 'label_block' => true,
123 'description' => sprintf(
124 '%s <a href="%s" target="_blank">%s</a>',
125 esc_html__('Select a pricing table or', 'king-addons'),
126 admin_url('admin.php?page=king-addons-pricing-tables&action=new'),
127 esc_html__('create a new one', 'king-addons')
128 ),
129 ]
130 );
131
132 $this->end_controls_section();
133
134 // Content Section - Display Options
135 $this->start_controls_section(
136 'section_display',
137 [
138 'label' => esc_html__('Display', 'king-addons'),
139 'tab' => Controls_Manager::TAB_CONTENT,
140 ]
141 );
142
143 $this->add_control(
144 'hide_toggle',
145 [
146 'label' => esc_html__('Hide Billing Toggle', 'king-addons'),
147 'type' => Controls_Manager::SWITCHER,
148 'default' => '',
149 'description' => esc_html__('Hide the monthly/annual toggle', 'king-addons'),
150 ]
151 );
152
153 $this->add_control(
154 'force_period',
155 [
156 'label' => esc_html__('Force Period', 'king-addons'),
157 'type' => Controls_Manager::SELECT,
158 'options' => [
159 '' => esc_html__('Default', 'king-addons'),
160 'monthly' => esc_html__('Monthly', 'king-addons'),
161 'annual' => esc_html__('Annual', 'king-addons'),
162 ],
163 'default' => '',
164 'description' => esc_html__('Force a specific billing period', 'king-addons'),
165 ]
166 );
167
168 $this->end_controls_section();
169
170 // Style Section - Layout
171 $this->start_controls_section(
172 'section_style_layout',
173 [
174 'label' => esc_html__('Layout', 'king-addons'),
175 'tab' => Controls_Manager::TAB_STYLE,
176 ]
177 );
178
179 $this->add_responsive_control(
180 'columns',
181 [
182 'label' => esc_html__('Columns', 'king-addons'),
183 'type' => Controls_Manager::SELECT,
184 'options' => [
185 '' => esc_html__('Default', 'king-addons'),
186 '1' => '1',
187 '2' => '2',
188 '3' => '3',
189 '4' => '4',
190 '5' => '5',
191 '6' => '6',
192 ],
193 'default' => '',
194 'tablet_default' => '',
195 'mobile_default' => '',
196 ]
197 );
198
199 $this->add_control(
200 'max_width',
201 [
202 'label' => esc_html__('Max Width', 'king-addons'),
203 'type' => Controls_Manager::SLIDER,
204 'size_units' => ['px', '%'],
205 'range' => [
206 'px' => [
207 'min' => 600,
208 'max' => 2000,
209 'step' => 10,
210 ],
211 '%' => [
212 'min' => 50,
213 'max' => 100,
214 ],
215 ],
216 'default' => [
217 'unit' => 'px',
218 'size' => '',
219 ],
220 ]
221 );
222
223 $this->add_responsive_control(
224 'alignment',
225 [
226 'label' => esc_html__('Alignment', 'king-addons'),
227 'type' => Controls_Manager::CHOOSE,
228 'options' => [
229 'left' => [
230 'title' => esc_html__('Left', 'king-addons'),
231 'icon' => 'eicon-text-align-left',
232 ],
233 'center' => [
234 'title' => esc_html__('Center', 'king-addons'),
235 'icon' => 'eicon-text-align-center',
236 ],
237 'right' => [
238 'title' => esc_html__('Right', 'king-addons'),
239 'icon' => 'eicon-text-align-right',
240 ],
241 ],
242 'default' => '',
243 ]
244 );
245
246 $this->end_controls_section();
247
248 // Style Section - Colors (Pro)
249 $this->start_controls_section(
250 'section_style_colors',
251 [
252 'label' => esc_html__('Colors', 'king-addons'),
253 'tab' => Controls_Manager::TAB_STYLE,
254 ]
255 );
256
257 $is_premium = function_exists('king_addons_freemius') && king_addons_freemius()->can_use_premium_code__premium_only();
258
259 if ($is_premium) {
260 $this->add_control(
261 'color_accent',
262 [
263 'label' => esc_html__('Accent Color', 'king-addons'),
264 'type' => Controls_Manager::COLOR,
265 'default' => '',
266 'selectors' => [
267 '{{WRAPPER}} .kng-pt-wrapper' => '--kng-pt-accent: {{VALUE}};',
268 ],
269 ]
270 );
271
272 $this->add_control(
273 'color_card_bg',
274 [
275 'label' => esc_html__('Card Background', 'king-addons'),
276 'type' => Controls_Manager::COLOR,
277 'default' => '',
278 'selectors' => [
279 '{{WRAPPER}} .kng-pt-wrapper' => '--kng-pt-card-bg: {{VALUE}};',
280 ],
281 ]
282 );
283
284 $this->add_control(
285 'color_text',
286 [
287 'label' => esc_html__('Text Color', 'king-addons'),
288 'type' => Controls_Manager::COLOR,
289 'default' => '',
290 'selectors' => [
291 '{{WRAPPER}} .kng-pt-wrapper' => '--kng-pt-text: {{VALUE}};',
292 ],
293 ]
294 );
295
296 $this->add_control(
297 'color_muted',
298 [
299 'label' => esc_html__('Muted Text Color', 'king-addons'),
300 'type' => Controls_Manager::COLOR,
301 'default' => '',
302 'selectors' => [
303 '{{WRAPPER}} .kng-pt-wrapper' => '--kng-pt-muted: {{VALUE}};',
304 ],
305 ]
306 );
307 } else {
308 $this->add_control(
309 'colors_pro_notice',
310 [
311 'type' => Controls_Manager::RAW_HTML,
312 'raw' => sprintf(
313 '<div style="padding: 15px; background: #f0f0f1; border-radius: 4px;">
314 <strong>%s</strong><br>%s <a href="%s" target="_blank">%s</a>
315 </div>',
316 esc_html__('Pro Feature', 'king-addons'),
317 esc_html__('Color overrides are available in the Pro version.', 'king-addons'),
318 'https://kingaddons.com/pricing/',
319 esc_html__('Upgrade Now', 'king-addons')
320 ),
321 ]
322 );
323 }
324
325 $this->end_controls_section();
326 }
327
328 /**
329 * Get pricing tables for select control.
330 *
331 * @return array
332 */
333 private function get_pricing_tables(): array
334 {
335 $tables = get_posts([
336 'post_type' => Pricing_Table_Builder::POST_TYPE,
337 'posts_per_page' => -1,
338 'post_status' => 'publish',
339 'orderby' => 'title',
340 'order' => 'ASC',
341 ]);
342
343 $options = ['' => esc_html__('Select a table', 'king-addons')];
344
345 foreach ($tables as $table) {
346 $options[$table->ID] = $table->post_title;
347 }
348
349 return $options;
350 }
351
352 /**
353 * Render widget output.
354 *
355 * @return void
356 */
357 protected function render(): void
358 {
359 $settings = $this->get_settings_for_display();
360 $table_id = (int)($settings['table_id'] ?? 0);
361
362 if (!$table_id) {
363 if (\Elementor\Plugin::$instance->editor->is_edit_mode()) {
364 echo '<div style="padding: 40px; text-align: center; background: #f5f5f7; border-radius: 12px;">';
365 echo '<p style="color: #86868b; margin: 0;">' . esc_html__('Please select a pricing table from the widget settings.', 'king-addons') . '</p>';
366 echo '</div>';
367 }
368 return;
369 }
370
371 $builder = Pricing_Table_Builder::instance();
372
373 $overrides = [];
374
375 if (!empty($settings['hide_toggle'])) {
376 $overrides['hide_toggle'] = true;
377 }
378
379 if (!empty($settings['force_period'])) {
380 $overrides['force_period'] = $settings['force_period'];
381 }
382
383 // Responsive columns
384 if (!empty($settings['columns'])) {
385 $overrides['columns_desktop'] = $settings['columns'];
386 }
387 if (!empty($settings['columns_tablet'])) {
388 $overrides['columns_tablet'] = $settings['columns_tablet'];
389 }
390 if (!empty($settings['columns_mobile'])) {
391 $overrides['columns_mobile'] = $settings['columns_mobile'];
392 }
393
394 if (!empty($settings['max_width']['size'])) {
395 $overrides['max_width'] = $settings['max_width']['size'];
396 }
397
398 if (!empty($settings['alignment'])) {
399 $overrides['alignment'] = $settings['alignment'];
400 }
401
402 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
403 echo $builder->render_for_elementor($table_id, $overrides);
404 }
405
406 /**
407 * Render widget output in the editor.
408 *
409 * @return void
410 */
411 protected function content_template(): void
412 {
413 ?>
414 <#
415 if (!settings.table_id) {
416 #>
417 <div style="padding: 40px; text-align: center; background: #f5f5f7; border-radius: 12px;">
418 <p style="color: #86868b; margin: 0;"><?php echo esc_html__('Please select a pricing table from the widget settings.', 'king-addons'); ?></p>
419 </div>
420 <#
421 }
422 #>
423 <?php
424 }
425 }
426