PluginProbe
King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder / 51.1.49
King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder v51.1.49
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 51.1.46 51.1.47 51.1.49 All 37 releases
king-addons / includes / widgets / Wishlist_Button / Wishlist_Button.php

Wishlist_Button.php in King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder 51.1.49, at includes/widgets/Wishlist_Button/Wishlist_Button.php

245 lines 6.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Wishlist Button 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 use Elementor\Widget_Base;
13 use King_Addons\Wishlist\Wishlist_Renderer;
14 use King_Addons\Wishlist\Wishlist_Service;
15 use King_Addons\Wishlist\Wishlist_Settings;
16
17 if (!defined('ABSPATH')) {
18 exit;
19 }
20
21 /**
22 * Renders the wishlist button widget.
23 */
24 class Wishlist_Button extends Widget_Base
25 {
26 /**
27 * Widget slug.
28 *
29 * @return string Widget name.
30 */
31 public function get_name(): string
32 {
33 return 'king-addons-wishlist-button';
34 }
35
36 /**
37 * Widget title.
38 *
39 * @return string Widget title.
40 */
41 public function get_title(): string
42 {
43 return esc_html__('Wishlist Button', 'king-addons');
44 }
45
46 /**
47 * Widget icon.
48 *
49 * @return string Icon class.
50 */
51 public function get_icon(): string
52 {
53 return 'king-addons-icon king-addons-wishlist-button';
54 }
55
56 /**
57 * Widget categories.
58 *
59 * @return array<int, string> Categories.
60 */
61 public function get_categories(): array
62 {
63 return ['king-addons', 'king-addons-woo-builder'];
64 }
65
66 /**
67 * Style dependencies.
68 *
69 * @return array<int, string> Style handles.
70 */
71 public function get_style_depends(): array
72 {
73 return [
74 'king-addons-wishlist',
75 ];
76 }
77
78 /**
79 * Script dependencies.
80 *
81 * @return array<int, string> Script handles.
82 */
83 public function get_script_depends(): array
84 {
85 return [
86 'king-addons-wishlist',
87 ];
88 }
89
90 /**
91 * Register widget controls.
92 *
93 * @return void
94 */
95 protected function register_controls(): void
96 {
97 $this->start_controls_section(
98 'kng_button_content',
99 [
100 'label' => esc_html__('Button', 'king-addons'),
101 'tab' => Controls_Manager::TAB_CONTENT,
102 ]
103 );
104
105 $this->add_control(
106 'kng_mode',
107 [
108 'label' => esc_html__('Product Source', 'king-addons'),
109 'type' => Controls_Manager::SELECT,
110 'options' => [
111 'auto' => esc_html__('Current product (single page)', 'king-addons'),
112 'manual' => esc_html__('Custom product ID', 'king-addons'),
113 ],
114 'default' => 'auto',
115 ]
116 );
117
118 $this->add_control(
119 'kng_product_id',
120 [
121 'label' => esc_html__('Product ID', 'king-addons'),
122 'type' => Controls_Manager::NUMBER,
123 'condition' => [
124 'kng_mode' => 'manual',
125 ],
126 ]
127 );
128
129 $this->add_control(
130 'kng_label_default',
131 [
132 'label' => esc_html__('Default text', 'king-addons'),
133 'type' => Controls_Manager::TEXT,
134 'default' => Wishlist_Settings::get('button_add_text'),
135 ]
136 );
137
138 $this->add_control(
139 'kng_label_added',
140 [
141 'label' => esc_html__('Added text', 'king-addons'),
142 'type' => Controls_Manager::TEXT,
143 'default' => Wishlist_Settings::get('button_added_text'),
144 ]
145 );
146
147 $this->add_control(
148 'kng_display_mode',
149 [
150 'label' => esc_html__('Display', 'king-addons'),
151 'type' => Controls_Manager::SELECT,
152 'options' => [
153 'icon_text' => esc_html__('Icon with text', 'king-addons'),
154 'icon' => esc_html__('Icon only', 'king-addons'),
155 ],
156 'default' => Wishlist_Settings::get('button_display_mode', 'icon_text'),
157 ]
158 );
159
160 $this->add_control(
161 'kng_icon_class',
162 [
163 'label' => esc_html__('Icon class', 'king-addons'),
164 'type' => Controls_Manager::TEXT,
165 'default' => Wishlist_Settings::get('icon_choice', 'eicon-heart'),
166 ]
167 );
168
169 $this->end_controls_section();
170
171 $this->start_controls_section(
172 'kng_button_style',
173 [
174 'label' => esc_html__('Style', 'king-addons'),
175 'tab' => Controls_Manager::TAB_STYLE,
176 ]
177 );
178
179 $this->add_control(
180 'kng_text_color',
181 [
182 'label' => esc_html__('Text color', 'king-addons'),
183 'type' => Controls_Manager::COLOR,
184 'selectors' => [
185 '{{WRAPPER}} .king-addons-wishlist-button' => 'color: {{VALUE}};',
186 ],
187 ]
188 );
189
190 $this->add_control(
191 'kng_background_color',
192 [
193 'label' => esc_html__('Background', 'king-addons'),
194 'type' => Controls_Manager::COLOR,
195 'selectors' => [
196 '{{WRAPPER}} .king-addons-wishlist-button' => 'background-color: {{VALUE}};',
197 ],
198 ]
199 );
200
201 $this->add_group_control(
202 Group_Control_Typography::get_type(),
203 [
204 'name' => 'kng_typography',
205 'selector' => '{{WRAPPER}} .king-addons-wishlist-button__label',
206 ]
207 );
208
209 $this->end_controls_section();
210 }
211
212 /**
213 * Render widget output.
214 *
215 * @return void
216 */
217 protected function render(): void
218 {
219 $settings = $this->get_settings_for_display();
220
221 $product_id = 'manual' === ($settings['kng_mode'] ?? 'auto')
222 ? absint($settings['kng_product_id'])
223 : get_the_ID();
224
225 if (!$product_id) {
226 echo esc_html__('Select a product to show wishlist button.', 'king-addons');
227 return;
228 }
229
230 $service = new Wishlist_Service();
231 $renderer = new Wishlist_Renderer($service);
232
233 echo $renderer->render_button([
234 'product_id' => $product_id,
235 'label_default' => $settings['kng_label_default'] ?? Wishlist_Settings::get('button_add_text'),
236 'label_added' => $settings['kng_label_added'] ?? Wishlist_Settings::get('button_added_text'),
237 'display_mode' => $settings['kng_display_mode'] ?? Wishlist_Settings::get('button_display_mode', 'icon_text'),
238 'icon_class' => $settings['kng_icon_class'] ?? Wishlist_Settings::get('icon_choice', 'eicon-heart'),
239 ]);
240 }
241 }
242
243
244
245