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_Order_Summary / Woo_Checkout_Order_Summary.php

Woo_Checkout_Order_Summary.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_Order_Summary/Woo_Checkout_Order_Summary.php

344 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 * Woo Checkout Order Summary widget.
4 *
5 * @package King_Addons
6 */
7
8 namespace King_Addons;
9
10 use Elementor\Controls_Manager;
11 use Elementor\Group_Control_Border;
12 use Elementor\Group_Control_Box_Shadow;
13 use Elementor\Group_Control_Typography;
14
15 if (!defined('ABSPATH')) {
16 exit;
17 }
18
19 /**
20 * Displays checkout order review section.
21 */
22 class Woo_Checkout_Order_Summary extends Abstract_Checkout_Widget
23 {
24 /**
25 * Widget slug.
26 *
27 * @return string
28 */
29 public function get_name(): string
30 {
31 return 'woo_checkout_order_summary';
32 }
33
34 /**
35 * Widget title.
36 *
37 * @return string
38 */
39 public function get_title(): string
40 {
41 return esc_html__('Checkout Order Summary', 'king-addons');
42 }
43
44 /**
45 * Widget icon.
46 *
47 * @return string
48 */
49 public function get_icon(): string
50 {
51 return 'king-addons-icon king-addons-woo-checkout-order-summary';
52 }
53
54 /**
55 * Categories.
56 *
57 * @return array<int, string>
58 */
59 public function get_categories(): array
60 {
61 return ['king-addons-woo-builder'];
62 }
63
64 /**
65 * Style dependencies.
66 *
67 * @return array<int, string>
68 */
69 public function get_style_depends(): array
70 {
71 return [KING_ADDONS_ASSETS_UNIQUE_KEY . '-woo-checkout-order-summary-style'];
72 }
73
74 /**
75 * Register controls.
76 *
77 * @return void
78 */
79 protected function register_controls(): void
80 {
81 $this->start_controls_section(
82 'section_content',
83 [
84 'label' => esc_html__('Content', 'king-addons'),
85 'tab' => Controls_Manager::TAB_CONTENT,
86 ]
87 );
88
89 $this->add_control(
90 'show_thumbnails',
91 [
92 'label' => sprintf(__('Show product thumbnails %s', 'king-addons'), '<i class="eicon-pro-icon"></i>'),
93 'type' => Controls_Manager::SWITCHER,
94 'return_value' => 'yes',
95 ]
96 );
97
98 $this->add_control(
99 'show_sku',
100 [
101 'label' => sprintf(__('Show SKU %s', 'king-addons'), '<i class="eicon-pro-icon"></i>'),
102 'type' => Controls_Manager::SWITCHER,
103 'return_value' => 'yes',
104 ]
105 );
106
107 $this->add_control(
108 'show_meta',
109 [
110 'label' => sprintf(__('Show item meta %s', 'king-addons'), '<i class="eicon-pro-icon"></i>'),
111 'type' => Controls_Manager::SWITCHER,
112 'return_value' => 'yes',
113 ]
114 );
115
116 $this->add_control(
117 'sticky',
118 [
119 'label' => sprintf(__('Make Sticky (Pro) %s', 'king-addons'), '<i class="eicon-pro-icon"></i>'),
120 'type' => Controls_Manager::SWITCHER,
121 'return_value' => 'yes',
122 ]
123 );
124
125 $this->add_control(
126 'sticky_offset',
127 [
128 'label' => sprintf(__('Sticky Offset (px) (Pro) %s', 'king-addons'), '<i class="eicon-pro-icon"></i>'),
129 'type' => Controls_Manager::NUMBER,
130 'default' => 20,
131 'condition' => [
132 'sticky' => 'yes',
133 ],
134 ]
135 );
136
137 $this->add_control(
138 'sticky_breakpoint',
139 [
140 'label' => sprintf(__('Sticky Breakpoint (px) (Pro) %s', 'king-addons'), '<i class="eicon-pro-icon"></i>'),
141 'type' => Controls_Manager::NUMBER,
142 'default' => 768,
143 'condition' => [
144 'sticky' => 'yes',
145 ],
146 ]
147 );
148
149 $this->end_controls_section();
150
151 $this->start_controls_section(
152 'section_style',
153 [
154 'label' => esc_html__('Box', 'king-addons'),
155 'tab' => Controls_Manager::TAB_STYLE,
156 ]
157 );
158
159 $this->add_group_control(
160 Group_Control_Typography::get_type(),
161 [
162 'name' => 'text_typography',
163 'selector' => '{{WRAPPER}} .ka-woo-checkout-summary',
164 ]
165 );
166
167 $this->add_control(
168 'text_color',
169 [
170 'label' => esc_html__('Text Color', 'king-addons'),
171 'type' => Controls_Manager::COLOR,
172 'selectors' => [
173 '{{WRAPPER}} .ka-woo-checkout-summary' => 'color: {{VALUE}};',
174 ],
175 ]
176 );
177
178 $this->add_group_control(
179 Group_Control_Border::get_type(),
180 [
181 'name' => 'box_border',
182 'selector' => '{{WRAPPER}} .ka-woo-checkout-summary',
183 ]
184 );
185
186 $this->add_group_control(
187 Group_Control_Box_Shadow::get_type(),
188 [
189 'name' => 'box_shadow',
190 'selector' => '{{WRAPPER}} .ka-woo-checkout-summary',
191 ]
192 );
193
194 $this->add_control(
195 'box_padding',
196 [
197 'label' => esc_html__('Padding', 'king-addons'),
198 'type' => Controls_Manager::DIMENSIONS,
199 'size_units' => ['px', 'em', '%'],
200 'selectors' => [
201 '{{WRAPPER}} .ka-woo-checkout-summary' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
202 ],
203 ]
204 );
205
206 $this->end_controls_section();
207 }
208
209 /**
210 * Render widget output.
211 *
212 * @return void
213 */
214 protected function render(): void
215 {
216 if (!$this->should_render()) {
217 $this->render_missing_checkout_notice();
218 return;
219 }
220
221 if (!function_exists('WC')) {
222 return;
223 }
224
225 $settings = $this->get_settings_for_display();
226 $can_pro = king_addons_can_use_pro();
227
228 $this->add_render_attribute('summary', 'class', 'ka-woo-checkout-summary');
229
230 $show_thumbs = !empty($settings['show_thumbnails']) && $can_pro;
231 $show_sku = !empty($settings['show_sku']) && $can_pro;
232 $show_meta = !empty($settings['show_meta']) && $can_pro;
233
234 if (!empty($settings['sticky']) && $can_pro) {
235 // A cleared field is '' rather than unset, and pinned the block to
236 // the very top instead of using the default offset.
237 $offset = max(0, (int) (($settings['sticky_offset'] ?? null) ?: 20));
238 $this->add_render_attribute('summary', 'class', 'ka-woo-checkout-summary--sticky');
239 $this->add_render_attribute('summary', 'data-ka-sticky', 'true');
240 $this->add_render_attribute('summary', 'data-ka-sticky-offset', (int) $offset);
241 $breakpoint = isset($settings['sticky_breakpoint']) ? (int) $settings['sticky_breakpoint'] : 768;
242 $this->add_render_attribute('summary', 'data-ka-sticky-breakpoint', (int) $breakpoint);
243 $this->add_render_attribute('summary', 'style', 'position: sticky; top: ' . $offset . 'px;');
244 }
245
246 $cart = WC()->cart;
247
248 if (!$cart || $cart->is_empty()) {
249 // Without a cart the widget printed an empty box - in the editor,
250 // where there is never a cart, that looks like a broken widget.
251 if (\Elementor\Plugin::$instance->editor->is_edit_mode()) {
252 echo '<div class="king-addons-woo-builder-notice">'
253 . esc_html__('The order summary lists what is in the cart at checkout.', 'king-addons')
254 . '</div>';
255 }
256 return;
257 }
258
259 echo '<div ' . $this->get_render_attribute_string('summary') . '>';
260 if ($cart) {
261 echo '<div class="ka-woo-checkout-summary__items">';
262 foreach ($cart->get_cart() as $cart_item_key => $cart_item) {
263 $product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key);
264 if (!$product || !$product->exists()) {
265 continue;
266 }
267 $product_id = $product->get_id();
268 $name = $product->get_name();
269 $qty = $cart_item['quantity'];
270 $line_total = $cart->get_product_subtotal($product, $qty);
271 $thumbnail = $show_thumbs ? $product->get_image('thumbnail') : '';
272 $sku = $show_sku ? $product->get_sku() : '';
273 $meta = $show_meta ? wc_get_formatted_cart_item_data($cart_item, false) : '';
274
275 echo '<div class="ka-woo-checkout-summary__item">';
276 if ($thumbnail) {
277 echo '<div class="ka-woo-checkout-summary__thumb">' . $thumbnail . '</div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
278 }
279 echo '<div class="ka-woo-checkout-summary__body">';
280 echo '<div class="ka-woo-checkout-summary__title">' . esc_html($name) . '</div>';
281 if ($sku) {
282 echo '<div class="ka-woo-checkout-summary__meta ka-woo-checkout-summary__meta--sku">' . esc_html__('SKU:', 'king-addons') . ' ' . esc_html($sku) . '</div>';
283 }
284 if ($meta) {
285 echo '<div class="ka-woo-checkout-summary__meta">' . wp_kses_post($meta) . '</div>';
286 }
287 echo '<div class="ka-woo-checkout-summary__qty">' . esc_html__('Qty:', 'king-addons') . ' ' . esc_html($qty) . '</div>';
288 echo '</div>';
289 echo '<div class="ka-woo-checkout-summary__price">' . wp_kses_post($line_total) . '</div>';
290 echo '</div>';
291 }
292 echo '</div>';
293
294 echo '<div class="ka-woo-checkout-summary__totals">';
295 echo '<div class="ka-woo-checkout-summary__totals-row"><span>' . esc_html__('Subtotal', 'king-addons') . '</span><span>' . wp_kses_post($cart->get_cart_subtotal()) . '</span></div>';
296
297 foreach ($cart->get_coupons() as $code => $coupon) {
298 // get_amount() is the coupon's configured value - for a percent
299 // coupon that is the percentage, so a 10% coupon printed
300 // "-10,00 €" instead of the discount it actually gave.
301 $amount_html = '-' . wc_price($cart->get_coupon_discount_amount($code, $cart->display_cart_ex_tax));
302 echo '<div class="ka-woo-checkout-summary__totals-row"><span>' . esc_html__('Coupon', 'king-addons') . ' (' . esc_html($code) . ')</span><span>' . wp_kses_post($amount_html) . '</span></div>';
303 }
304
305 if ($cart->needs_shipping() && $cart->show_shipping()) {
306 $packages = WC()->shipping()->get_packages();
307 WC()->shipping()->calculate_shipping($packages);
308 $rates = $packages[0]['rates'] ?? [];
309 $chosen = WC()->session ? WC()->session->get('chosen_shipping_methods') : [];
310 $chosen_id = $chosen[0] ?? '';
311 foreach ($rates as $rate) {
312 if ($chosen_id && $rate->id !== $chosen_id) {
313 continue;
314 }
315 echo '<div class="ka-woo-checkout-summary__totals-row"><span>' . esc_html__('Shipping', 'king-addons') . '</span><span>' . wp_kses_post(wc_price($rate->get_cost())) . '</span></div>';
316 }
317 }
318
319 foreach ($cart->get_fees() as $fee) {
320 echo '<div class="ka-woo-checkout-summary__totals-row"><span>' . esc_html($fee->name) . '</span><span>' . wp_kses_post(wc_price($fee->amount)) . '</span></div>';
321 }
322
323 if ('excl' === $cart->get_tax_price_display_mode()) {
324 $tax_totals = $cart->get_tax_totals();
325 if (!empty($tax_totals)) {
326 foreach ($tax_totals as $code => $tax) {
327 echo '<div class="ka-woo-checkout-summary__totals-row"><span>' . esc_html($tax->label) . '</span><span>' . wp_kses_post($tax->formatted_amount) . '</span></div>';
328 }
329 }
330 }
331
332 echo '<div class="ka-woo-checkout-summary__totals-row ka-woo-checkout-summary__totals-row--total"><span>' . esc_html__('Total', 'king-addons') . '</span><span>' . wp_kses_post($cart->get_total()) . '</span></div>';
333 echo '</div>';
334 }
335 echo '</div>';
336 }
337 }
338
339
340
341
342
343
344