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_Related / Woo_Product_Related.php

Woo_Product_Related.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_Related/Woo_Product_Related.php

105 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Woo Product Related widget.
4 *
5 * @package King_Addons
6 */
7
8 namespace King_Addons;
9
10 use Elementor\Controls_Manager;
11
12 if (!defined('ABSPATH')) {
13 exit;
14 }
15
16 /**
17 * Displays related products grid.
18 */
19 class Woo_Product_Related extends Abstract_Single_Widget
20 {
21 public function get_name(): string
22 {
23 return 'woo_product_related';
24 }
25
26 public function get_title(): string
27 {
28 return esc_html__('Related Products', 'king-addons');
29 }
30
31 public function get_icon(): string
32 {
33 return 'eicon-products';
34 }
35
36 public function get_categories(): array
37 {
38 return ['king-addons-woo-builder'];
39 }
40
41 protected function register_controls(): void
42 {
43 $this->start_controls_section(
44 'section_content',
45 [
46 'label' => esc_html__('Content', 'king-addons'),
47 'tab' => Controls_Manager::TAB_CONTENT,
48 ]
49 );
50
51 $this->add_control(
52 'products_limit',
53 [
54 'label' => esc_html__('Products limit', 'king-addons'),
55 'type' => Controls_Manager::NUMBER,
56 'default' => 4,
57 'min' => 1,
58 ]
59 );
60
61 $this->add_control(
62 'columns',
63 [
64 'label' => esc_html__('Columns', 'king-addons'),
65 'type' => Controls_Manager::NUMBER,
66 'default' => 4,
67 'min' => 1,
68 'max' => 6,
69 ]
70 );
71
72 $this->end_controls_section();
73 }
74
75 protected function render(): void
76 {
77 $product = $this->get_product();
78 if (!$product) {
79 $this->render_missing_product_notice();
80 return;
81 }
82
83 $settings = $this->get_settings_for_display();
84 $limit = max(1, (int) ($settings['products_limit'] ?? 4));
85 $columns = max(1, min(6, (int) ($settings['columns'] ?? 4)));
86
87 $related_ids = wc_get_related_products($product->get_id(), $limit);
88 if (empty($related_ids)) {
89 return;
90 }
91
92 $shortcode = sprintf('[products ids="%s" columns="%d"]', implode(',', $related_ids), $columns);
93 echo '<div class="ka-woo-related">';
94 echo do_shortcode($shortcode); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
95 echo '</div>';
96 }
97 }
98
99
100
101
102
103
104
105