PluginProbe
King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder / 51.1.86
King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder v51.1.86
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_Checkout_Steps / Woo_Checkout_Steps.php

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

273 lines 8.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Woo Checkout Steps widget (multi-step).
4 *
5 * @package King_Addons
6 */
7
8 namespace King_Addons;
9
10 use Elementor\Controls_Manager;
11 use Elementor\Widget_Base;
12 use King_Addons\Woo_Builder\Context as Woo_Context;
13
14 if (!defined('ABSPATH')) {
15 exit;
16 }
17
18 /**
19 * Placeholder multi-step checkout (Free shows notice, Pro overrides).
20 */
21 class Woo_Checkout_Steps extends Widget_Base
22 {
23 /**
24 * Register Pro-only controls (placeholder).
25 *
26 * Pro overrides this method to add premium controls without using parent::register_controls().
27 *
28 * @return void
29 */
30 public function register_pro_controls(): void
31 {
32 // Intentionally empty in Free.
33 }
34
35 /**
36 * Widget slug.
37 *
38 * @return string
39 */
40 public function get_name(): string
41 {
42 return 'woo_checkout_steps';
43 }
44
45 /**
46 * Widget title.
47 *
48 * @return string
49 */
50 public function get_title(): string
51 {
52 return esc_html__('Checkout Steps (Multi-step)', 'king-addons');
53 }
54
55 /**
56 * Widget icon.
57 *
58 * @return string
59 */
60 public function get_icon(): string
61 {
62 return 'king-addons-icon king-addons-woo-checkout-steps';
63 }
64
65 /**
66 * Widget categories.
67 *
68 * @return array<int,string>
69 */
70 public function get_categories(): array
71 {
72 return ['king-addons-woo-builder'];
73 }
74
75 /**
76 * Styles.
77 *
78 * @return array<int, string>
79 */
80 public function get_style_depends(): array
81 {
82 return [KING_ADDONS_ASSETS_UNIQUE_KEY . '-woo-checkout-steps-style'];
83 }
84
85 /**
86 * Scripts.
87 *
88 * @return array<int, string>
89 */
90 public function get_script_depends(): array
91 {
92 return [KING_ADDONS_ASSETS_UNIQUE_KEY . '-woo-checkout-steps-script'];
93 }
94
95 /**
96 * Register controls.
97 *
98 * @return void
99 */
100 public function get_custom_help_url()
101 {
102 return 'mailto:[email protected]?subject=Bug Report - King Addons&body=Please describe the issue';
103 }
104
105 protected function register_controls(): void
106 {
107 $this->start_controls_section(
108 'section_content',
109 [
110 'label' => esc_html__('Content', 'king-addons'),
111 'tab' => Controls_Manager::TAB_CONTENT,
112 ]
113 );
114
115 $this->add_control(
116 'steps',
117 [
118 'label' => esc_html__('Steps', 'king-addons'),
119 'type' => Controls_Manager::REPEATER,
120 'fields' => [
121 [
122 'name' => 'label',
123 'label' => esc_html__('Label', 'king-addons'),
124 'type' => Controls_Manager::TEXT,
125 'default' => esc_html__('Step', 'king-addons'),
126 ],
127 [
128 'name' => 'target',
129 'label' => sprintf(__('Target selector (Pro) %s', 'king-addons'), '<i class="eicon-pro-icon"></i>'),
130 'type' => Controls_Manager::TEXT,
131 'placeholder' => '#customer_details',
132 ],
133 ],
134 'default' => [
135 ['label' => esc_html__('Billing', 'king-addons')],
136 ['label' => esc_html__('Shipping', 'king-addons')],
137 ['label' => esc_html__('Payment', 'king-addons')],
138 ['label' => esc_html__('Review', 'king-addons')],
139 ],
140 ]
141 );
142
143 $this->add_control(
144 'scroll_to_section',
145 [
146 'label' => sprintf(__('Scroll to section (Pro) %s', 'king-addons'), '<i class="eicon-pro-icon"></i>'),
147 'type' => Controls_Manager::SWITCHER,
148 'return_value' => 'yes',
149 ]
150 );
151
152 $this->add_control(
153 'show_nav',
154 [
155 'label' => sprintf(__('Show Next/Previous (Pro) %s', 'king-addons'), '<i class="eicon-pro-icon"></i>'),
156 'type' => Controls_Manager::SWITCHER,
157 'return_value' => 'yes',
158 ]
159 );
160
161 $this->add_control(
162 'auto_scroll',
163 [
164 'label' => esc_html__('Scroll on step change (Pro)', 'king-addons'),
165 'type' => Controls_Manager::SWITCHER,
166 'return_value' => 'yes',
167 ]
168 );
169
170 $this->add_control(
171 'prev_text',
172 [
173 'label' => esc_html__('Previous text', 'king-addons'),
174 'type' => Controls_Manager::TEXT,
175 'dynamic' => ['active' => true],
176 'default' => esc_html__('Previous', 'king-addons'),
177 'condition' => [
178 'show_nav' => 'yes',
179 ],
180 ]
181 );
182
183 $this->add_control(
184 'next_text',
185 [
186 'label' => esc_html__('Next text', 'king-addons'),
187 'type' => Controls_Manager::TEXT,
188 'dynamic' => ['active' => true],
189 'default' => esc_html__('Next', 'king-addons'),
190 'condition' => [
191 'show_nav' => 'yes',
192 ],
193 ]
194 );
195
196 $this->end_controls_section();
197
198 // Allow Pro to add additional controls without using parent::register_controls().
199 $this->register_pro_controls();
200 }
201
202 /**
203 * Render widget output (free shows upgrade notice).
204 *
205 * @return void
206 */
207 protected function render(): void
208 {
209 if (!Woo_Context::maybe_render_context_notice('checkout')) {
210 return;
211 }
212
213 $in_builder = class_exists('King_Addons\\Woo_Builder\\Context') && Woo_Context::is_editing_template_type('checkout');
214 if (!function_exists('is_checkout') || (!is_checkout() && !$in_builder) || (function_exists('is_order_received_page') && is_order_received_page())) {
215 return;
216 }
217
218 if (!king_addons_can_use_pro()) {
219 if (Woo_Context::is_editor()) {
220 echo '<div class="king-addons-woo-builder-notice">';
221 echo esc_html__('Multi-step checkout is available in Pro.', 'king-addons');
222 echo '</div>';
223 }
224 return;
225 }
226
227 $settings = $this->get_settings_for_display();
228 $steps = $settings['steps'] ?? [];
229 if (empty($steps)) {
230 if (\Elementor\Plugin::$instance->editor->is_edit_mode()) {
231 echo '<div class="king-addons-woo-builder-notice">'
232 . esc_html__('Add at least one step, each pointing at a section of the checkout.', 'king-addons')
233 . '</div>';
234 }
235 return;
236 }
237
238 $scroll = (!empty($settings['scroll_to_section']) && 'yes' === $settings['scroll_to_section']) ? 'yes' : 'no';
239 $auto_scroll = (!empty($settings['auto_scroll']) && 'yes' === $settings['auto_scroll']) ? 'yes' : 'no';
240 $show_nav = (!empty($settings['show_nav']) && 'yes' === $settings['show_nav']);
241 // ?: not ??: a cleared field is '' rather than null, which left the
242 // navigation buttons unlabelled. The values are escaped at output, so
243 // the fallbacks must not be pre-escaped.
244 $prev_text = ($settings['prev_text'] ?? null) ?: __('Previous', 'king-addons');
245 $next_text = ($settings['next_text'] ?? null) ?: __('Next', 'king-addons');
246
247 echo '<div class="ka-woo-checkout-steps-wrapper" data-enable-nav="' . ($show_nav ? 'true' : 'false') . '" data-auto-scroll="' . esc_attr($auto_scroll) . '">';
248 echo '<ol class="ka-woo-checkout-steps ka-woo-checkout-steps--pro" role="list" data-scroll-top="' . esc_attr($scroll) . '" data-prev-text="' . esc_attr($prev_text) . '" data-next-text="' . esc_attr($next_text) . '">';
249 foreach ($steps as $index => $step) {
250 $label = $step['label'] ?? '';
251 $target = $step['target'] ?? '';
252 echo '<li class="ka-woo-checkout-step" data-step="' . esc_attr((string) ($index + 1)) . '" data-target="' . esc_attr($target) . '">';
253 echo '<span class="ka-woo-checkout-step__number">' . esc_html((string) ($index + 1)) . '</span>';
254 echo '<span class="ka-woo-checkout-step__label">' . esc_html($label) . '</span>';
255 echo '</li>';
256 }
257 echo '</ol>';
258 if ($show_nav) {
259 echo '<div class="ka-woo-checkout-steps__nav">';
260 echo '<button type="button" class="button ka-woo-checkout-steps__prev" data-nav="prev">' . esc_html($prev_text) . '</button>';
261 echo '<button type="button" class="button button-primary ka-woo-checkout-steps__next" data-nav="next">' . esc_html($next_text) . '</button>';
262 echo '</div>';
263 }
264 echo '</div>';
265 }
266 }
267
268
269
270
271
272
273