PluginProbe
King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder / 51.1.85
King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder v51.1.85
51.1.87 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 All 41 releases
king-addons / includes / widgets / Woo_Cart_Cross_Sells / Woo_Cart_Cross_Sells.php

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

311 lines 8.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Woo Cart Cross-sells 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 * Renders cart cross-sell products.
21 */
22 class Woo_Cart_Cross_Sells extends Abstract_Cart_Widget
23 {
24 /**
25 * Widget slug.
26 *
27 * @return string
28 */
29 public function get_name(): string
30 {
31 return 'woo_cart_cross_sells';
32 }
33
34 /**
35 * Widget title.
36 *
37 * @return string
38 */
39 public function get_title(): string
40 {
41 return esc_html__('Cart Cross-sells', '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-cart-cross-sells';
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-loop-style', KING_ADDONS_ASSETS_UNIQUE_KEY . '-woo-cart-cross-sells-style'];
72 }
73
74 /**
75 * Script dependencies.
76 *
77 * @return array<int, string>
78 */
79 public function get_script_depends(): array
80 {
81 return [
82 KING_ADDONS_ASSETS_UNIQUE_KEY . '-slick-slick',
83 KING_ADDONS_ASSETS_UNIQUE_KEY . '-woo-cart-cross-sells-script',
84 ];
85 }
86
87 /**
88 * Register controls.
89 *
90 * @return void
91 */
92 protected function register_controls(): void
93 {
94 $this->start_controls_section(
95 'section_content',
96 [
97 'label' => esc_html__('Content', 'king-addons'),
98 'tab' => Controls_Manager::TAB_CONTENT,
99 ]
100 );
101
102 $this->add_control(
103 'limit',
104 [
105 'label' => esc_html__('Products Limit', 'king-addons'),
106 'type' => Controls_Manager::NUMBER,
107 'min' => 1,
108 'default' => 4,
109 ]
110 );
111
112 $this->add_control(
113 'columns',
114 [
115 'label' => esc_html__('Columns', 'king-addons'),
116 'type' => Controls_Manager::NUMBER,
117 'min' => 1,
118 'max' => 6,
119 'default' => 4,
120 ]
121 );
122
123 $this->add_control(
124 'columns_tablet',
125 [
126 'label' => esc_html__('Columns Tablet', 'king-addons'),
127 'type' => Controls_Manager::NUMBER,
128 'min' => 1,
129 'max' => 4,
130 'default' => 2,
131 ]
132 );
133
134 $this->add_control(
135 'columns_mobile',
136 [
137 'label' => esc_html__('Columns Mobile', 'king-addons'),
138 'type' => Controls_Manager::NUMBER,
139 'min' => 1,
140 'max' => 2,
141 'default' => 1,
142 ]
143 );
144
145 $this->add_control(
146 'show_heading',
147 [
148 'label' => esc_html__('Show heading', 'king-addons'),
149 'type' => Controls_Manager::SWITCHER,
150 'return_value' => 'yes',
151 'default' => 'yes',
152 ]
153 );
154
155 $this->add_control(
156 'heading_text',
157 [
158 'label' => esc_html__('Heading text', 'king-addons'),
159 'type' => Controls_Manager::TEXT,
160 'dynamic' => ['active' => true],
161 'default' => __('You may also like…', 'king-addons'),
162 'condition' => [
163 'show_heading' => 'yes',
164 ],
165 ]
166 );
167
168 $this->add_control(
169 'show_arrows',
170 [
171 'label' => esc_html__('Show Arrows', 'king-addons'),
172 'type' => Controls_Manager::SWITCHER,
173 'return_value' => 'yes',
174 'default' => 'yes',
175 ]
176 );
177
178 $this->add_control(
179 'show_dots',
180 [
181 'label' => esc_html__('Show Dots', 'king-addons'),
182 'type' => Controls_Manager::SWITCHER,
183 'return_value' => 'yes',
184 'default' => '',
185 ]
186 );
187
188 $this->add_control(
189 'loop',
190 [
191 'label' => esc_html__('Loop Slides', 'king-addons'),
192 'type' => Controls_Manager::SWITCHER,
193 'return_value' => 'yes',
194 'default' => '',
195 ]
196 );
197
198 $this->add_control(
199 'autoplay',
200 [
201 'label' => esc_html__('Autoplay', 'king-addons'),
202 'type' => Controls_Manager::SWITCHER,
203 'return_value' => 'yes',
204 'default' => '',
205 ]
206 );
207
208 $this->add_control(
209 'autoplay_speed',
210 [
211 'label' => esc_html__('Autoplay Speed (ms)', 'king-addons'),
212 'type' => Controls_Manager::NUMBER,
213 'default' => 4000,
214 'condition' => [
215 'autoplay' => 'yes',
216 ],
217 ]
218 );
219
220 $this->end_controls_section();
221
222 $this->start_controls_section(
223 'section_style',
224 [
225 'label' => esc_html__('Card', 'king-addons'),
226 'tab' => Controls_Manager::TAB_STYLE,
227 ]
228 );
229
230 $this->add_group_control(
231 Group_Control_Typography::get_type(),
232 [
233 'name' => 'title_typography',
234 'selector' => '{{WRAPPER}} .cross-sells',
235 ]
236 );
237
238 $this->add_group_control(
239 Group_Control_Border::get_type(),
240 [
241 'name' => 'card_border',
242 'selector' => '{{WRAPPER}} .cross-sells li.product',
243 ]
244 );
245
246 $this->add_group_control(
247 Group_Control_Box_Shadow::get_type(),
248 [
249 'name' => 'card_shadow',
250 'selector' => '{{WRAPPER}} .cross-sells li.product',
251 ]
252 );
253
254 $this->end_controls_section();
255 }
256
257 /**
258 * Render widget output.
259 *
260 * @return void
261 */
262 protected function render(): void
263 {
264 if (!$this->should_render()) {
265 $this->render_missing_cart_notice();
266 return;
267 }
268
269 if (!function_exists('WC') || !WC()->cart || WC()->cart->is_empty()) {
270 // Printing WooCommerce's whole empty-cart template from a
271 // cross-sells widget duplicated the message the cart itself already
272 // shows. Say nothing on the front end; explain in the editor.
273 if (\Elementor\Plugin::$instance->editor->is_edit_mode()) {
274 echo '<div class="king-addons-woo-builder-notice">'
275 . esc_html__('Cross-sells are listed for the products in the cart.', 'king-addons')
276 . '</div>';
277 }
278 return;
279 }
280
281 $settings = $this->get_settings_for_display();
282 // ?: not ??: a cleared number field is '' rather than null, and
283 // (int) '' is 0 - every one of these collapsed to a single column.
284 $limit = max(1, (int) (($settings['limit'] ?? null) ?: 4));
285 $columns = max(1, (int) (($settings['columns'] ?? null) ?: 4));
286 $columns_tablet = max(1, (int) (($settings['columns_tablet'] ?? null) ?: 2));
287 $columns_mobile = max(1, (int) (($settings['columns_mobile'] ?? null) ?: 1));
288 $show_arrows = !empty($settings['show_arrows']);
289 $show_dots = !empty($settings['show_dots']);
290 $loop = !empty($settings['loop']);
291 $autoplay = !empty($settings['autoplay']);
292 $autoplay_speed = max(500, (int) (($settings['autoplay_speed'] ?? null) ?: 4000));
293 $heading_text = (!empty($settings['show_heading']) && !empty($settings['heading_text'])) ? $settings['heading_text'] : '';
294
295 echo '<div class="ka-woo-cart-cross-sells" data-ka-cross-sell="1" data-cols="' . esc_attr((string) $columns) . '" data-cols-tablet="' . esc_attr((string) $columns_tablet) . '" data-cols-mobile="' . esc_attr((string) $columns_mobile) . '" data-arrows="' . ($show_arrows ? '1' : '0') . '" data-dots="' . ($show_dots ? '1' : '0') . '" data-loop="' . ($loop ? '1' : '0') . '" data-autoplay="' . ($autoplay ? '1' : '0') . '" data-autoplay-speed="' . esc_attr((string) $autoplay_speed) . '">';
296 if ($heading_text) {
297 echo '<h3 class="ka-woo-cart-cross-sells__heading">' . esc_html($heading_text) . '</h3>';
298 }
299 echo '<div class="ka-woo-cart-cross-sells__list">';
300 woocommerce_cross_sell_display($limit, $columns);
301 echo '</div>';
302 echo '</div>';
303 }
304 }
305
306
307
308
309
310
311