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_Counter / Wishlist_Counter.php

Wishlist_Counter.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_Counter/Wishlist_Counter.php

214 lines 5.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Wishlist Counter 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 a wishlist counter widget.
23 */
24 class Wishlist_Counter 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-counter';
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 Counter', '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-counter';
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 controls.
97 *
98 * @return void
99 */
100 protected function register_controls(): void
101 {
102 $this->start_controls_section(
103 'kng_counter_content',
104 [
105 'label' => esc_html__('Counter', 'king-addons'),
106 'tab' => Controls_Manager::TAB_CONTENT,
107 ]
108 );
109
110 $this->add_control(
111 'kng_click_action',
112 [
113 'label' => esc_html__('Click action', 'king-addons'),
114 'type' => Controls_Manager::SELECT,
115 'options' => [
116 'none' => esc_html__('None', 'king-addons'),
117 'wishlist_page' => esc_html__('Go to wishlist page', 'king-addons'),
118 'custom' => esc_html__('Custom URL', 'king-addons'),
119 ],
120 'default' => 'wishlist_page',
121 ]
122 );
123
124 $this->add_control(
125 'kng_custom_url',
126 [
127 'label' => esc_html__('Custom URL', 'king-addons'),
128 'type' => Controls_Manager::URL,
129 'placeholder' => 'https://',
130 'condition' => [
131 'kng_click_action' => 'custom',
132 ],
133 ]
134 );
135
136 $this->end_controls_section();
137
138 $this->start_controls_section(
139 'kng_counter_style',
140 [
141 'label' => esc_html__('Style', 'king-addons'),
142 'tab' => Controls_Manager::TAB_STYLE,
143 ]
144 );
145
146 $this->add_control(
147 'kng_counter_color',
148 [
149 'label' => esc_html__('Text color', 'king-addons'),
150 'type' => Controls_Manager::COLOR,
151 'selectors' => [
152 '{{WRAPPER}} .king-addons-wishlist-counter' => 'color: {{VALUE}};',
153 ],
154 ]
155 );
156
157 $this->add_control(
158 'kng_counter_background',
159 [
160 'label' => esc_html__('Background', 'king-addons'),
161 'type' => Controls_Manager::COLOR,
162 'selectors' => [
163 '{{WRAPPER}} .king-addons-wishlist-counter' => 'background-color: {{VALUE}};',
164 ],
165 ]
166 );
167
168 $this->add_group_control(
169 Group_Control_Typography::get_type(),
170 [
171 'name' => 'kng_counter_typography',
172 'selector' => '{{WRAPPER}} .king-addons-wishlist-counter',
173 ]
174 );
175
176 $this->end_controls_section();
177 }
178
179 /**
180 * Render counter output.
181 *
182 * @return void
183 */
184 protected function render(): void
185 {
186 $settings = $this->get_settings_for_display();
187 $service = new Wishlist_Service();
188 $renderer = new Wishlist_Renderer($service);
189
190 $counter_markup = $renderer->render_counter([]);
191 $action = $settings['kng_click_action'] ?? 'wishlist_page';
192
193 if ('custom' === $action && !empty($settings['kng_custom_url']['url'])) {
194 $this->add_link_attributes('kng_custom_url', $settings['kng_custom_url']);
195 echo '<a ' . $this->get_render_attribute_string('kng_custom_url') . '>' . $counter_markup . '</a>';
196 return;
197 }
198
199 if ('wishlist_page' === $action) {
200 $page_id = Wishlist_Settings::wishlist_page_id();
201 if ($page_id) {
202 $url = get_permalink($page_id);
203 echo '<a href="' . esc_url($url) . '">' . $counter_markup . '</a>';
204 return;
205 }
206 }
207
208 echo $counter_markup;
209 }
210 }
211
212
213
214