PluginProbe
King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder / 51.1.63
King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder v51.1.63
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_Product_Meta / Woo_Product_Meta.php

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

389 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 Product Meta widget.
4 *
5 * @package King_Addons
6 */
7
8 namespace King_Addons;
9
10 use Elementor\Controls_Manager;
11 use Elementor\Group_Control_Typography;
12
13 if (!defined('ABSPATH')) {
14 exit;
15 }
16
17 /**
18 * Displays product meta info (categories, tags, optional SKU/brand).
19 */
20 class Woo_Product_Meta extends Abstract_Single_Widget
21 {
22 public function get_name(): string
23 {
24 return 'woo_product_meta';
25 }
26
27 public function get_title(): string
28 {
29 return esc_html__('Product Meta', 'king-addons');
30 }
31
32 public function get_icon(): string
33 {
34 return 'eicon-meta-data';
35 }
36
37 public function get_categories(): array
38 {
39 return ['king-addons-woo-builder'];
40 }
41
42 public function get_style_depends(): array
43 {
44 return [KING_ADDONS_ASSETS_UNIQUE_KEY . '-woo-product-meta-style'];
45 }
46
47 protected function register_controls(): void
48 {
49 $this->start_controls_section(
50 'section_content',
51 [
52 'label' => esc_html__('Content', 'king-addons'),
53 'tab' => Controls_Manager::TAB_CONTENT,
54 ]
55 );
56
57 $this->add_control(
58 'show_categories',
59 [
60 'label' => esc_html__('Show categories', 'king-addons'),
61 'type' => Controls_Manager::SWITCHER,
62 'return_value' => 'yes',
63 'default' => 'yes',
64 ]
65 );
66
67 $this->add_control(
68 'show_tags',
69 [
70 'label' => esc_html__('Show tags', 'king-addons'),
71 'type' => Controls_Manager::SWITCHER,
72 'return_value' => 'yes',
73 'default' => 'yes',
74 ]
75 );
76
77 $this->add_control(
78 'show_sku',
79 [
80 'label' => sprintf(__('Show SKU %s', 'king-addons'), '<i class="eicon-pro-icon"></i>'),
81 'type' => Controls_Manager::SWITCHER,
82 'return_value' => 'yes',
83 ]
84 );
85
86 $this->add_control(
87 'show_brand',
88 [
89 'label' => sprintf(__('Show brand taxonomy %s', 'king-addons'), '<i class="eicon-pro-icon"></i>'),
90 'type' => Controls_Manager::SWITCHER,
91 'return_value' => 'yes',
92 ]
93 );
94
95 $this->add_control(
96 'brand_taxonomy',
97 [
98 'label' => esc_html__('Brand taxonomy (Pro)', 'king-addons'),
99 'type' => Controls_Manager::TEXT,
100 'default' => 'product_brand',
101 'condition' => [
102 'show_brand' => 'yes',
103 ],
104 ]
105 );
106
107 $this->add_control(
108 'brand_fallback_taxonomy',
109 [
110 'label' => esc_html__('Brand fallback taxonomy (Pro)', 'king-addons'),
111 'type' => Controls_Manager::TEXT,
112 'default' => 'pa_brand',
113 'condition' => [
114 'show_brand' => 'yes',
115 ],
116 ]
117 );
118
119 $this->add_control(
120 'layout',
121 [
122 'label' => sprintf(__('Layout %s', 'king-addons'), '<i class="eicon-pro-icon"></i>'),
123 'type' => Controls_Manager::SELECT,
124 'options' => [
125 'inline' => esc_html__('Inline', 'king-addons'),
126 'stacked' => esc_html__('Stacked (Pro)', 'king-addons'),
127 'inline_no_label' => esc_html__('Inline, no labels (Pro)', 'king-addons'),
128 ],
129 'default' => 'inline',
130 ]
131 );
132
133 $this->add_control(
134 'format_preset',
135 [
136 'label' => sprintf(__('Format preset %s', 'king-addons'), '<i class="eicon-pro-icon"></i>'),
137 'type' => Controls_Manager::SELECT,
138 'options' => [
139 '' => esc_html__('Default', 'king-addons'),
140 'pipe' => esc_html__('Pipe inline', 'king-addons'),
141 'bullets' => esc_html__('Bullets', 'king-addons'),
142 'badges' => esc_html__('Badges', 'king-addons'),
143 ],
144 'default' => '',
145 ]
146 );
147
148 $this->add_control(
149 'separator',
150 [
151 'label' => esc_html__('Separator', 'king-addons'),
152 'type' => Controls_Manager::TEXT,
153 'default' => ', ',
154 ]
155 );
156
157 $this->add_control(
158 'label_categories',
159 [
160 'label' => esc_html__('Label: Categories', 'king-addons'),
161 'type' => Controls_Manager::TEXT,
162 'default' => esc_html__('Category:', 'king-addons'),
163 ]
164 );
165
166 $this->add_control(
167 'label_tags',
168 [
169 'label' => esc_html__('Label: Tags', 'king-addons'),
170 'type' => Controls_Manager::TEXT,
171 'default' => esc_html__('Tags:', 'king-addons'),
172 ]
173 );
174
175 $this->add_control(
176 'label_brand',
177 [
178 'label' => esc_html__('Label: Brand (Pro)', 'king-addons'),
179 'type' => Controls_Manager::TEXT,
180 'default' => esc_html__('Brand:', 'king-addons'),
181 ]
182 );
183
184 $this->add_control(
185 'label_sku',
186 [
187 'label' => esc_html__('Label: SKU (Pro)', 'king-addons'),
188 'type' => Controls_Manager::TEXT,
189 'default' => esc_html__('SKU:', 'king-addons'),
190 ]
191 );
192
193 $this->add_control(
194 'label_transform',
195 [
196 'label' => sprintf(__('Label transform %s', 'king-addons'), '<i class="eicon-pro-icon"></i>'),
197 'type' => Controls_Manager::SELECT,
198 'options' => [
199 '' => esc_html__('None', 'king-addons'),
200 'uppercase' => esc_html__('Uppercase', 'king-addons'),
201 'caps' => esc_html__('Capitalize', 'king-addons'),
202 ],
203 'default' => '',
204 ]
205 );
206
207 $this->end_controls_section();
208
209 $this->start_controls_section(
210 'section_style',
211 [
212 'label' => esc_html__('Style', 'king-addons'),
213 'tab' => Controls_Manager::TAB_STYLE,
214 ]
215 );
216
217 $this->add_group_control(
218 Group_Control_Typography::get_type(),
219 [
220 'name' => 'label_typo',
221 'selector' => '{{WRAPPER}} .ka-woo-product-meta__label',
222 'label' => esc_html__('Label Typography', 'king-addons'),
223 ]
224 );
225
226 $this->add_control(
227 'label_color',
228 [
229 'label' => esc_html__('Label Color', 'king-addons'),
230 'type' => Controls_Manager::COLOR,
231 'selectors' => [
232 '{{WRAPPER}} .ka-woo-product-meta__label' => 'color: {{VALUE}};',
233 ],
234 ]
235 );
236
237 $this->add_group_control(
238 Group_Control_Typography::get_type(),
239 [
240 'name' => 'value_typo',
241 'selector' => '{{WRAPPER}} .ka-woo-product-meta__value',
242 'label' => esc_html__('Value Typography', 'king-addons'),
243 ]
244 );
245
246 $this->add_control(
247 'value_color',
248 [
249 'label' => esc_html__('Value Color', 'king-addons'),
250 'type' => Controls_Manager::COLOR,
251 'selectors' => [
252 '{{WRAPPER}} .ka-woo-product-meta__value' => 'color: {{VALUE}};',
253 '{{WRAPPER}} .ka-woo-product-meta__value a' => 'color: {{VALUE}};',
254 ],
255 ]
256 );
257
258 $this->add_responsive_control(
259 'item_gap',
260 [
261 'label' => esc_html__('Items gap', 'king-addons'),
262 'type' => Controls_Manager::SLIDER,
263 'range' => [
264 'px' => ['min' => 0, 'max' => 30],
265 ],
266 'selectors' => [
267 '{{WRAPPER}} .ka-woo-product-meta__item' => 'margin-bottom: {{SIZE}}{{UNIT}};',
268 ],
269 ]
270 );
271
272 $this->end_controls_section();
273 }
274
275 protected function render(): void
276 {
277 if (!class_exists('WooCommerce') || !function_exists('wc_get_product_category_list') || !function_exists('wc_get_product_tag_list')) {
278 return;
279 }
280
281 $product = $this->get_product();
282 if (!$product) {
283 $this->render_missing_product_notice();
284 return;
285 }
286
287 $settings = $this->get_settings_for_display();
288 $can_pro = king_addons_can_use_pro();
289
290 $items = [];
291 $sep = sanitize_text_field((string) ($settings['separator'] ?? ', '));
292
293 if (!empty($settings['show_categories'])) {
294 $cats = wc_get_product_category_list($product->get_id(), $sep);
295 if ($cats) {
296 $items[] = [
297 'label' => $settings['label_categories'] ?: esc_html__('Category:', 'king-addons'),
298 'value' => $cats,
299 ];
300 }
301 }
302
303 if (!empty($settings['show_tags'])) {
304 $tags = wc_get_product_tag_list($product->get_id(), $sep);
305 if ($tags) {
306 $items[] = [
307 'label' => $settings['label_tags'] ?: esc_html__('Tags:', 'king-addons'),
308 'value' => $tags,
309 ];
310 }
311 }
312
313 if (!empty($settings['show_sku']) && $can_pro) {
314 $sku = $product->get_sku();
315 if ($sku) {
316 $items[] = [
317 'label' => $settings['label_sku'] ?: esc_html__('SKU:', 'king-addons'),
318 'value' => esc_html($sku),
319 ];
320 }
321 }
322
323 if (!empty($settings['show_brand']) && $can_pro) {
324 $taxes = [];
325 if (!empty($settings['brand_taxonomy'])) {
326 $taxes[] = sanitize_key($settings['brand_taxonomy']);
327 }
328 if (!empty($settings['brand_fallback_taxonomy'])) {
329 $taxes[] = sanitize_key($settings['brand_fallback_taxonomy']);
330 }
331 $taxes = array_unique(array_filter($taxes));
332 foreach ($taxes as $tax) {
333 $terms = get_the_terms($product->get_id(), $tax);
334 if (!empty($terms) && !is_wp_error($terms)) {
335 $links = [];
336 foreach ($terms as $term) {
337 $links[] = '<a href="' . esc_url(get_term_link($term)) . '">' . esc_html($term->name) . '</a>';
338 }
339 $items[] = [
340 'label' => $settings['label_brand'] ?: esc_html__('Brand:', 'king-addons'),
341 'value' => implode($sep, $links),
342 ];
343 break;
344 }
345 }
346 }
347
348 if (empty($items)) {
349 return;
350 }
351
352 $layout = $settings['layout'] ?? 'inline';
353 if (in_array($layout, ['stacked', 'inline_no_label'], true) && !$can_pro) {
354 $layout = 'inline';
355 }
356
357 $format_preset = $settings['format_preset'] ?? '';
358 if (!empty($format_preset) && !$can_pro) {
359 $format_preset = '';
360 }
361
362 $wrapper_classes = ['ka-woo-product-meta', 'ka-woo-product-meta--' . $layout];
363 if (!empty($format_preset)) {
364 $wrapper_classes[] = 'ka-woo-product-meta--format-' . sanitize_html_class($format_preset);
365 }
366 if (!empty($settings['label_transform']) && $can_pro) {
367 $wrapper_classes[] = 'ka-woo-product-meta--label-' . sanitize_html_class($settings['label_transform']);
368 }
369
370 echo '<div class="' . esc_attr(implode(' ', $wrapper_classes)) . '">';
371 foreach ($items as $item) {
372 echo '<div class="ka-woo-product-meta__item">';
373 if ('inline_no_label' !== $layout) {
374 echo '<span class="ka-woo-product-meta__label">' . esc_html($item['label']) . '</span> ';
375 }
376 echo '<span class="ka-woo-product-meta__value">' . wp_kses_post($item['value']) . '</span>';
377 echo '</div>';
378 }
379 echo '</div>';
380 }
381 }
382
383
384
385
386
387
388
389