PluginProbe
King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder / 51.1.84
King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder v51.1.84
51.1.86 51.1.84 51.1.85 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 All 40 releases
king-addons / includes / widgets / Facet_Price / Facet_Price.php

Facet_Price.php in King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder 51.1.84, at includes/widgets/Facet_Price/Facet_Price.php

275 lines 9.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Facet Price widget.
4 *
5 * @package King_Addons
6 */
7
8 namespace King_Addons;
9
10 use Elementor\Controls_Manager;
11 use Elementor\Widget_Base;
12
13 if (!defined('ABSPATH')) {
14 exit;
15 }
16
17 /**
18 * Price range filter widget.
19 */
20 class Facet_Price extends Widget_Base
21 {
22 /**
23 * Widget slug.
24 *
25 * @return string
26 */
27 public function get_name(): string
28 {
29 return 'king-addons-facet-price';
30 }
31
32 /**
33 * Widget title.
34 *
35 * @return string
36 */
37 public function get_title(): string
38 {
39 return esc_html__('Price Filter', 'king-addons');
40 }
41
42 /**
43 * Keywords.
44 *
45 * @return array<int, string>
46 */
47 public function get_keywords(): array
48 {
49 return ['shop', 'product', 'filter', 'filters', 'ajax', 'woocommerce', 'price', 'range', 'faceted', 'smart filters'];
50 }
51
52 /**
53 * Widget icon.
54 *
55 * @return string
56 */
57 public function get_icon(): string
58 {
59 return 'king-addons-icon king-addons-facet-price';
60 }
61
62 /**
63 * Categories.
64 *
65 * @return array<int, string>
66 */
67 public function get_categories(): array
68 {
69 return ['king-addons'];
70 }
71
72 /**
73 * Style dependencies.
74 *
75 * @return array<int, string>
76 */
77 public function get_style_depends(): array
78 {
79 return [
80 KING_ADDONS_ASSETS_UNIQUE_KEY . '-facet-price-style',
81 ];
82 }
83
84 /**
85 * Script dependencies.
86 *
87 * @return array<int, string>
88 */
89 public function get_script_depends(): array
90 {
91 return [
92 KING_ADDONS_ASSETS_UNIQUE_KEY . '-facet-price-script',
93 ];
94 }
95
96 public function get_custom_help_url()
97 {
98 return 'mailto:[email protected]?subject=Bug Report - King Addons&body=Please describe the issue';
99 }
100
101 /**
102 * Register controls.
103 *
104 * @return void
105 */
106 public function register_controls(): void
107 {
108 $this->start_controls_section(
109 'kng_facet_price_section',
110 [
111 'label' => KING_ADDONS_ELEMENTOR_ICON . esc_html__('Price Filter', 'king-addons'),
112 'tab' => Controls_Manager::TAB_CONTENT,
113 ]
114 );
115
116 $this->add_control(
117 'kng_filters_query_id',
118 [
119 'label' => esc_html__('Shop Filters ID', 'king-addons'),
120 'type' => Controls_Manager::TEXT,
121 'placeholder' => esc_html__('shop_grid_1', 'king-addons'),
122 'description' => esc_html__('Must match the Shop Filters ID on the product grid.', 'king-addons'),
123 ]
124 );
125
126 $this->add_control(
127 'kng_min_value',
128 [
129 'label' => esc_html__('Minimum Price', 'king-addons'),
130 'type' => Controls_Manager::NUMBER,
131 'default' => 0,
132 ]
133 );
134
135 $this->add_control(
136 'kng_max_value',
137 [
138 'label' => esc_html__('Maximum Price', 'king-addons'),
139 'type' => Controls_Manager::NUMBER,
140 'default' => 100,
141 ]
142 );
143
144 $this->add_control(
145 'kng_step',
146 [
147 'label' => esc_html__('Step', 'king-addons'),
148 'type' => Controls_Manager::NUMBER,
149 'default' => 1,
150 'min' => 0.1,
151 ]
152 );
153
154 $this->add_control(
155 'kng_variable_price',
156 [
157 'label' => esc_html__('Variable products', 'king-addons'),
158 'type' => Controls_Manager::SELECT,
159 'default' => 'any',
160 'options' => [
161 'any' => esc_html__('Match if any variation is in range', 'king-addons'),
162 'displayed' => esc_html__('Match by the price shown on the card', 'king-addons'),
163 ],
164 'description' => esc_html__('A variable product may show “from €150” while other variations cost more. “Any variation” keeps it in the results when a shopper filters from €250 and a €260 option exists. “Card price” uses only the number on the card, usually the minimum.', 'king-addons'),
165 ]
166 );
167
168 $this->end_controls_section();
169
170 require_once KING_ADDONS_PATH . 'includes/helpers/Faceted/Style_Controls.php';
171 Facet_Style_Controls::fields($this, '{{WRAPPER}} .king-addons-facet--price .king-addons-facet__input');
172 Facet_Style_Controls::buckets($this);
173 }
174
175 /**
176 * Render widget output.
177 *
178 * @return void
179 */
180 public function render(): void
181 {
182 $settings = $this->get_settings_for_display();
183 $query_id = sanitize_title($settings['kng_filters_query_id'] ?? '');
184
185 if ('' === $query_id) {
186 return;
187 }
188
189 $min = isset($settings['kng_min_value']) ? (float) $settings['kng_min_value'] : 0;
190 $max = isset($settings['kng_max_value']) ? (float) $settings['kng_max_value'] : 0;
191 $step = isset($settings['kng_step']) ? (float) $settings['kng_step'] : 1;
192 $variable_price = (($settings['kng_variable_price'] ?? 'any') === 'displayed') ? 'displayed' : 'any';
193 $show_buckets = true;
194
195 ?>
196 <div class="king-addons-facet king-addons-facet--price" data-ka-filters-query-id="<?php echo esc_attr($query_id); ?>" data-ka-variable-price="<?php echo esc_attr($variable_price); ?>">
197 <div class="king-addons-facet__row">
198 <label class="king-addons-facet__label">
199 <?php echo esc_html__('Min', 'king-addons'); ?>
200 <input
201 type="number"
202 class="king-addons-facet__input"
203 data-ka-filter-type="price"
204 data-ka-price-role="min"
205 data-ka-filters-query-id="<?php echo esc_attr($query_id); ?>"
206 step="<?php echo esc_attr($step); ?>"
207 value="<?php echo esc_attr($min); ?>"
208 />
209 </label>
210 <label class="king-addons-facet__label">
211 <?php echo esc_html__('Max', 'king-addons'); ?>
212 <input
213 type="number"
214 class="king-addons-facet__input"
215 data-ka-filter-type="price"
216 data-ka-price-role="max"
217 data-ka-filters-query-id="<?php echo esc_attr($query_id); ?>"
218 step="<?php echo esc_attr($step); ?>"
219 value="<?php echo esc_attr($max); ?>"
220 />
221 </label>
222 </div>
223 <?php if ($show_buckets) : ?>
224 <ul class="king-addons-facet__buckets" data-ka-filters-query-id="<?php echo esc_attr($query_id); ?>">
225 <?php
226 $buckets = apply_filters(
227 'king_addons/faceted_filters/price_buckets',
228 [
229 ['min' => 0, 'max' => 25],
230 ['min' => 25, 'max' => 50],
231 ['min' => 50, 'max' => 100],
232 ['min' => 100, 'max' => 250],
233 ['min' => 250, 'max' => 999999],
234 ],
235 'woo_products_grid'
236 );
237 foreach ($buckets as $bucket) :
238 $bucket_min = isset($bucket['min']) ? (float) $bucket['min'] : 0;
239 $bucket_max = isset($bucket['max']) ? (float) $bucket['max'] : 999999;
240 $bucket_key = $bucket_min . '-' . $bucket_max;
241 if ($bucket_max >= 999999) {
242 $label = sprintf('%s+', wc_price($bucket_min));
243 } else {
244 $label = sprintf('%s - %s', wc_price($bucket_min), wc_price($bucket_max));
245 }
246 ?>
247 <li class="king-addons-facet__bucket">
248 <button
249 type="button"
250 class="king-addons-facet__bucket-btn"
251 data-ka-filter-type="price-bucket"
252 data-ka-filters-query-id="<?php echo esc_attr($query_id); ?>"
253 data-ka-price-bucket="<?php echo esc_attr($bucket_key); ?>"
254 data-ka-price-min="<?php echo esc_attr((string) $bucket_min); ?>"
255 data-ka-price-max="<?php echo esc_attr((string) $bucket_max); ?>"
256 data-ka-price-label="<?php echo esc_attr(wp_strip_all_tags($label)); ?>"
257 >
258 <span class="king-addons-facet__bucket-label"><?php echo wp_kses_post($label); ?></span>
259 <span class="king-addons-facet__bucket-count" data-ka-price-bucket="<?php echo esc_attr($bucket_key); ?>"></span>
260 </button>
261 </li>
262 <?php endforeach; ?>
263 </ul>
264 <?php endif; ?>
265 </div>
266 <?php
267 }
268 }
269
270
271
272
273
274
275