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 / Woo_Archive_Description / Woo_Archive_Description.php

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

213 lines 5.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Woo Archive Description 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
13 if (!defined('ABSPATH')) {
14 exit;
15 }
16
17 /**
18 * Displays archive description.
19 */
20 class Woo_Archive_Description extends Abstract_Archive_Widget
21 {
22 public function get_name(): string
23 {
24 return 'woo_archive_description';
25 }
26
27 public function get_title(): string
28 {
29 return esc_html__('Archive Description', 'king-addons');
30 }
31
32 public function get_icon(): string
33 {
34 return 'eicon-editor-paragraph';
35 }
36
37 public function get_categories(): array
38 {
39 return ['king-addons-woo-builder'];
40 }
41
42 public function get_style_depends(): array
43 {
44 return [KING_ADDONS_ASSETS_UNIQUE_KEY . '-woo-archive-description-style'];
45 }
46
47 protected function register_controls(): void
48 {
49 $this->start_controls_section(
50 'section_content',
51 [
52 'label' => esc_html__('Content', 'king-addons'),
53 'tab' => Controls_Manager::TAB_CONTENT,
54 ]
55 );
56
57 $this->add_control(
58 'trim_words',
59 [
60 'label' => sprintf(__('Trim words %s', 'king-addons'), '<i class="eicon-pro-icon"></i>'),
61 'type' => Controls_Manager::NUMBER,
62 'min' => 10,
63 ]
64 );
65
66 $this->add_control(
67 'read_more_text',
68 [
69 'label' => esc_html__('Read more text (Pro)', 'king-addons'),
70 'type' => Controls_Manager::TEXT,
71 'default' => esc_html__('Read more', 'king-addons'),
72 ]
73 );
74
75 $this->add_control(
76 'format',
77 [
78 'label' => sprintf(__('Custom format %s', 'king-addons'), '<i class="eicon-pro-icon"></i>'),
79 'type' => Controls_Manager::TEXTAREA,
80 'description' => esc_html__('Use {description}, {title}, {count}.', 'king-addons'),
81 'rows' => 3,
82 ]
83 );
84
85 $this->add_control(
86 'source',
87 [
88 'label' => sprintf(__('Source %s', 'king-addons'), '<i class="eicon-pro-icon"></i>'),
89 'type' => Controls_Manager::SELECT,
90 'options' => [
91 'auto' => esc_html__('Auto (term/shop description)', 'king-addons'),
92 'custom' => esc_html__('Custom text', 'king-addons'),
93 ],
94 'default' => 'auto',
95 ]
96 );
97
98 $this->add_control(
99 'custom_text',
100 [
101 'label' => esc_html__('Custom text', 'king-addons'),
102 'type' => Controls_Manager::TEXTAREA,
103 'rows' => 4,
104 'condition' => [
105 'source' => 'custom',
106 ],
107 ]
108 );
109
110 $this->end_controls_section();
111
112 $this->start_controls_section(
113 'section_style',
114 [
115 'label' => esc_html__('Style', 'king-addons'),
116 'tab' => Controls_Manager::TAB_STYLE,
117 ]
118 );
119
120 $this->add_group_control(
121 Group_Control_Typography::get_type(),
122 [
123 'name' => 'typography',
124 'selector' => '{{WRAPPER}} .ka-woo-archive-description',
125 ]
126 );
127
128 $this->add_control(
129 'color',
130 [
131 'label' => esc_html__('Color', 'king-addons'),
132 'type' => Controls_Manager::COLOR,
133 'selectors' => [
134 '{{WRAPPER}} .ka-woo-archive-description' => 'color: {{VALUE}};',
135 ],
136 ]
137 );
138
139 $this->add_responsive_control(
140 'margin',
141 [
142 'label' => esc_html__('Margin', 'king-addons'),
143 'type' => Controls_Manager::DIMENSIONS,
144 'size_units' => ['px', 'em', '%'],
145 'selectors' => [
146 '{{WRAPPER}} .ka-woo-archive-description' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
147 ],
148 ]
149 );
150
151 $this->end_controls_section();
152 }
153
154 protected function render(): void
155 {
156 if (!is_shop() && !is_product_taxonomy()) {
157 $this->render_missing_archive_notice();
158 return;
159 }
160
161 $settings = $this->get_settings_for_display();
162 $can_pro = king_addons_can_use_pro();
163
164 $desc = '';
165 $title = woocommerce_page_title(false);
166 if ('custom' === ($settings['source'] ?? 'auto')) {
167 $desc = $settings['custom_text'] ?? '';
168 } else {
169 $desc = term_description();
170 if (is_shop()) {
171 $shop_id = wc_get_page_id('shop');
172 $desc = get_post_field('post_content', $shop_id);
173 }
174 }
175
176 if (empty($desc)) {
177 return;
178 }
179
180 $trim = !empty($settings['trim_words']) && $can_pro ? (int) $settings['trim_words'] : 0;
181 $trimmed = false;
182 if ($trim > 0) {
183 $trimmed = true;
184 $desc = wp_trim_words(wp_strip_all_tags($desc), $trim, '');
185 $desc = wpautop($desc);
186 }
187
188 if (!empty($settings['format']) && $can_pro) {
189 global $wp_query;
190 $count = isset($wp_query->found_posts) ? (int) $wp_query->found_posts : 0;
191 $desc = str_replace(
192 ['{description}', '{title}', '{count}'],
193 [$desc, $title, number_format_i18n($count)],
194 $settings['format']
195 );
196 }
197
198 echo '<div class="ka-woo-archive-description">';
199 echo wp_kses_post($desc);
200 if ($trimmed && !empty($settings['read_more_text']) && $can_pro) {
201 echo '<a class="ka-woo-archive-description__readmore" href="#">' . esc_html($settings['read_more_text']) . '</a>';
202 }
203 echo '</div>';
204 }
205 }
206
207
208
209
210
211
212
213