PluginProbe
King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder / 51.1.78
King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder v51.1.78
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 / Woo_Archive_Banner / Woo_Archive_Banner.php

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

286 lines 8.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Woo Archive Banner widget.
4 *
5 * @package King_Addons
6 */
7
8 namespace King_Addons;
9
10 use Elementor\Controls_Manager;
11 use Elementor\Group_Control_Image_Size;
12 use Elementor\Group_Control_Typography;
13 use Elementor\Utils;
14
15 if (!defined('ABSPATH')) {
16 exit;
17 }
18
19 /**
20 * Displays archive banner.
21 */
22 class Woo_Archive_Banner extends Abstract_Archive_Widget
23 {
24 public function get_name(): string
25 {
26 return 'woo_archive_banner';
27 }
28
29 public function get_title(): string
30 {
31 return esc_html__('Archive Banner', 'king-addons');
32 }
33
34 public function get_icon(): string
35 {
36 return 'eicon-banner';
37 }
38
39 public function get_categories(): array
40 {
41 return ['king-addons-woo-builder'];
42 }
43
44 public function get_style_depends(): array
45 {
46 return [KING_ADDONS_ASSETS_UNIQUE_KEY . '-woo-archive-banner-style'];
47 }
48
49 protected function register_controls(): void
50 {
51 $this->start_controls_section(
52 'section_content',
53 [
54 'label' => esc_html__('Content', 'king-addons'),
55 'tab' => Controls_Manager::TAB_CONTENT,
56 ]
57 );
58
59 $this->add_control(
60 'image',
61 [
62 'label' => esc_html__('Image', 'king-addons'),
63 'type' => Controls_Manager::MEDIA,
64 'default' => [
65 'url' => Utils::get_placeholder_image_src(),
66 ],
67 ]
68 );
69
70 $this->add_group_control(
71 Group_Control_Image_Size::get_type(),
72 [
73 'name' => 'image_size',
74 'default' => 'large',
75 ]
76 );
77
78 $this->add_control(
79 'title',
80 [
81 'label' => esc_html__('Title', 'king-addons'),
82 'type' => Controls_Manager::TEXT,
83 'default' => esc_html__('Archive Banner', 'king-addons'),
84 ]
85 );
86
87 $this->add_control(
88 'description',
89 [
90 'label' => esc_html__('Description', 'king-addons'),
91 'type' => Controls_Manager::TEXTAREA,
92 'default' => esc_html__('Highlight your category or shop with a banner.', 'king-addons'),
93 ]
94 );
95
96 $this->add_control(
97 'button_text',
98 [
99 'label' => esc_html__('Button Text', 'king-addons'),
100 'type' => Controls_Manager::TEXT,
101 'default' => '',
102 ]
103 );
104
105 $this->add_control(
106 'button_url',
107 [
108 'label' => esc_html__('Button URL', 'king-addons'),
109 'type' => Controls_Manager::URL,
110 'placeholder' => 'https://',
111 ]
112 );
113
114 $this->add_control(
115 'use_term_meta',
116 [
117 'label' => sprintf(__('Use term meta (Pro) %s', 'king-addons'), '<i class="eicon-pro-icon"></i>'),
118 'type' => Controls_Manager::SWITCHER,
119 'return_value' => 'yes',
120 ]
121 );
122
123 $this->add_control(
124 'title_format',
125 [
126 'label' => sprintf(__('Title format %s', 'king-addons'), '<i class="eicon-pro-icon"></i>'),
127 'type' => Controls_Manager::TEXT,
128 'description' => esc_html__('Use {title} and {count}.', 'king-addons'),
129 ]
130 );
131
132 $this->add_control(
133 'desc_format',
134 [
135 'label' => sprintf(__('Description format %s', 'king-addons'), '<i class="eicon-pro-icon"></i>'),
136 'type' => Controls_Manager::TEXTAREA,
137 'description' => esc_html__('Use {description}, {title}, {count}.', 'king-addons'),
138 ]
139 );
140
141 $this->end_controls_section();
142
143 $this->start_controls_section(
144 'section_style',
145 [
146 'label' => esc_html__('Style', 'king-addons'),
147 'tab' => Controls_Manager::TAB_STYLE,
148 ]
149 );
150
151 $this->add_group_control(
152 Group_Control_Typography::get_type(),
153 [
154 'name' => 'title_typo',
155 'selector' => '{{WRAPPER}} .ka-woo-archive-banner__title',
156 ]
157 );
158
159 $this->add_control(
160 'title_color',
161 [
162 'label' => esc_html__('Title Color', 'king-addons'),
163 'type' => Controls_Manager::COLOR,
164 'selectors' => [
165 '{{WRAPPER}} .ka-woo-archive-banner__title' => 'color: {{VALUE}};',
166 ],
167 ]
168 );
169
170 $this->add_group_control(
171 Group_Control_Typography::get_type(),
172 [
173 'name' => 'desc_typo',
174 'selector' => '{{WRAPPER}} .ka-woo-archive-banner__desc',
175 ]
176 );
177
178 $this->add_control(
179 'desc_color',
180 [
181 'label' => esc_html__('Description Color', 'king-addons'),
182 'type' => Controls_Manager::COLOR,
183 'selectors' => [
184 '{{WRAPPER}} .ka-woo-archive-banner__desc' => 'color: {{VALUE}};',
185 ],
186 ]
187 );
188
189 $this->add_responsive_control(
190 'padding',
191 [
192 'label' => esc_html__('Padding', 'king-addons'),
193 'type' => Controls_Manager::DIMENSIONS,
194 'size_units' => ['px', 'em', '%'],
195 'selectors' => [
196 '{{WRAPPER}} .ka-woo-archive-banner__inner' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
197 ],
198 ]
199 );
200
201 $this->end_controls_section();
202 }
203
204 protected function render(): void
205 {
206 if (!class_exists('WooCommerce') || !function_exists('is_shop') || !function_exists('is_product_taxonomy')) {
207 return;
208 }
209
210 if (!$this->should_render()) {
211 $this->render_missing_archive_notice();
212 return;
213 }
214
215 $settings = $this->get_settings_for_display();
216 $can_pro = king_addons_can_use_pro();
217
218 $title = $settings['title'] ?? '';
219 $desc = $settings['description'] ?? '';
220 $img_html = '';
221
222 if (!empty($settings['use_term_meta']) && $can_pro && is_product_taxonomy()) {
223 $term = get_queried_object();
224 $term_img_id = get_term_meta($term->term_id, 'banner_image', true);
225 $term_title = get_term_meta($term->term_id, 'banner_title', true);
226 $term_desc = get_term_meta($term->term_id, 'banner_desc', true);
227 if ($term_img_id) {
228 $img_html = Group_Control_Image_Size::get_attachment_image_html($settings, 'image_size', $term_img_id);
229 }
230 if ($term_title) {
231 $title = $term_title;
232 }
233 if ($term_desc) {
234 $desc = $term_desc;
235 }
236 }
237
238 if ($can_pro) {
239 global $wp_query;
240 $count = isset($wp_query->found_posts) ? (int) $wp_query->found_posts : 0;
241 if (!empty($settings['title_format'])) {
242 $title = str_replace(
243 ['{title}', '{count}'],
244 [$title, number_format_i18n($count)],
245 $settings['title_format']
246 );
247 }
248 if (!empty($settings['desc_format'])) {
249 $desc = str_replace(
250 ['{description}', '{title}', '{count}'],
251 [$desc, $title, number_format_i18n($count)],
252 $settings['desc_format']
253 );
254 }
255 }
256
257 if (empty($img_html) && !empty($settings['image']['id'])) {
258 $img_html = Group_Control_Image_Size::get_attachment_image_html($settings, 'image_size', $settings['image']['id']);
259 }
260
261 echo '<div class="ka-woo-archive-banner">';
262 if ($img_html) {
263 echo '<div class="ka-woo-archive-banner__image">' . $img_html . '</div>';
264 }
265 echo '<div class="ka-woo-archive-banner__inner">';
266 if ($title) {
267 echo '<h3 class="ka-woo-archive-banner__title">' . esc_html($title) . '</h3>';
268 }
269 if ($desc) {
270 echo '<div class="ka-woo-archive-banner__desc">' . wp_kses_post($desc) . '</div>';
271 }
272 if (!empty($settings['button_text']) && !empty($settings['button_url']['url'])) {
273 $target = $settings['button_url']['is_external'] ? ' target="_blank" rel="noopener noreferrer"' : '';
274 echo '<a class="ka-woo-archive-banner__btn" href="' . esc_url($settings['button_url']['url']) . '"' . $target . '>' . esc_html($settings['button_text']) . '</a>';
275 }
276 echo '</div>';
277 echo '</div>';
278 }
279 }
280
281
282
283
284
285
286