PluginProbe
King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder / 51.1.83
King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder v51.1.83
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.83, at includes/widgets/Wishlist_Button/Wishlist_Button.php

255 lines 6.9 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-woo'];
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 public function get_custom_help_url()
91 {
92 return 'mailto:bug@kingaddons.com?subject=Bug Report - King Addons&body=Please describe the issue';
93 }
94
95 /**
96 * Register widget controls.
97 *
98 * @return void
99 */
100 protected function register_controls(): void
101 {
102 $this->start_controls_section(
103 'kng_button_content',
104 [
105 'label' => esc_html__('Button', 'king-addons'),
106 'tab' => Controls_Manager::TAB_CONTENT,
107 ]
108 );
109
110 $this->add_control(
111 'kng_mode',
112 [
113 'label' => esc_html__('Product Source', 'king-addons'),
114 'type' => Controls_Manager::SELECT,
115 'options' => [
116 'auto' => esc_html__('Current product (single page)', 'king-addons'),
117 'manual' => esc_html__('Custom product ID', 'king-addons'),
118 ],
119 'default' => 'auto',
120 ]
121 );
122
123 $this->add_control(
124 'kng_product_id',
125 [
126 'label' => esc_html__('Product ID', 'king-addons'),
127 'type' => Controls_Manager::NUMBER,
128 'condition' => [
129 'kng_mode' => 'manual',
130 ],
131 ]
132 );
133
134 $this->add_control(
135 'kng_label_default',
136 [
137 'label' => esc_html__('Default text', 'king-addons'),
138 'type' => Controls_Manager::TEXT,
139 'default' => Wishlist_Settings::get('button_add_text'),
140 ]
141 );
142
143 $this->add_control(
144 'kng_label_added',
145 [
146 'label' => esc_html__('Added text', 'king-addons'),
147 'type' => Controls_Manager::TEXT,
148 'default' => Wishlist_Settings::get('button_added_text'),
149 ]
150 );
151
152 $this->add_control(
153 'kng_display_mode',
154 [
155 'label' => esc_html__('Display', 'king-addons'),
156 'type' => Controls_Manager::SELECT,
157 'options' => [
158 'icon_text' => esc_html__('Icon with text', 'king-addons'),
159 'icon' => esc_html__('Icon only', 'king-addons'),
160 ],
161 'default' => Wishlist_Settings::get('button_display_mode', 'icon_text'),
162 ]
163 );
164
165 $this->add_control(
166 'kng_icon_class',
167 [
168 'label' => esc_html__('Icon class', 'king-addons'),
169 'type' => Controls_Manager::TEXT,
170 'default' => Wishlist_Settings::get('icon_choice', 'fas fa-heart'),
171 ]
172 );
173
174 $this->end_controls_section();
175
176 $this->start_controls_section(
177 'kng_button_style',
178 [
179 'label' => esc_html__('Style', 'king-addons'),
180 'tab' => Controls_Manager::TAB_STYLE,
181 ]
182 );
183
184 $this->add_control(
185 'kng_text_color',
186 [
187 'label' => esc_html__('Text color', 'king-addons'),
188 'type' => Controls_Manager::COLOR,
189 'selectors' => [
190 '{{WRAPPER}} .king-addons-wishlist-button' => 'color: {{VALUE}};',
191 ],
192 ]
193 );
194
195 $this->add_control(
196 'kng_background_color',
197 [
198 'label' => esc_html__('Background', 'king-addons'),
199 'type' => Controls_Manager::COLOR,
200 'selectors' => [
201 '{{WRAPPER}} .king-addons-wishlist-button' => 'background-color: {{VALUE}};',
202 ],
203 ]
204 );
205
206 $this->add_group_control(
207 Group_Control_Typography::get_type(),
208 [
209 'name' => 'kng_typography',
210 'selector' => '{{WRAPPER}} .king-addons-wishlist-button__label',
211 ]
212 );
213
214 $this->end_controls_section();
215 }
216
217 /**
218 * Render widget output.
219 *
220 * @return void
221 */
222 protected function render(): void
223 {
224 $settings = $this->get_settings_for_display();
225
226 $product_id = 'manual' === ($settings['kng_mode'] ?? 'auto')
227 ? absint($settings['kng_product_id'])
228 : get_the_ID();
229
230 if (!$product_id) {
231 echo esc_html__('Select a product to show wishlist button.', 'king-addons');
232 return;
233 }
234
235 if (function_exists('wc_get_product') && !wc_get_product($product_id)) {
236 echo esc_html__('Select a product to show wishlist button.', 'king-addons');
237 return;
238 }
239
240 $service = new Wishlist_Service();
241 $renderer = new Wishlist_Renderer($service);
242
243 echo Wishlist_Renderer::kses($renderer->render_button([
244 'product_id' => $product_id,
245 'label_default' => $settings['kng_label_default'] ?? Wishlist_Settings::get('button_add_text'),
246 'label_added' => $settings['kng_label_added'] ?? Wishlist_Settings::get('button_added_text'),
247 'display_mode' => $settings['kng_display_mode'] ?? Wishlist_Settings::get('button_display_mode', 'icon_text'),
248 'icon_class' => $settings['kng_icon_class'] ?? Wishlist_Settings::get('icon_choice', 'fas fa-heart'),
249 ]));
250 }
251 }
252
253
254
255