| @@ -35,12 +35,22 @@ | ||
| 35 | 35 | * @return string |
| 36 | 36 | */ |
| 37 | 37 | public function get_title(): string |
| 38 | 38 | { |
| 39 | - return esc_html__('Facet Price', 'king-addons'); | |
| 39 | + return esc_html__('Price Filter', 'king-addons'); | |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 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 | + /** | |
| 43 | 53 | * Widget icon. |
| 44 | 54 | * |
| 45 | 55 | * @return string |
| 46 | 56 | */ |
| @@ -45,9 +55,9 @@ | ||
| 45 | 55 | * @return string |
| 46 | 56 | */ |
| 47 | 57 | public function get_icon(): string |
| 48 | 58 | { |
| 49 | - return 'eicon-range-slider'; | |
| 59 | + return 'king-addons-icon king-addons-facet-price'; | |
| 50 | 60 | } |
| 51 | 61 | |
| 52 | 62 | /** |
| 53 | 63 | * Categories. |
| @@ -97,9 +107,9 @@ | ||
| 97 | 107 | { |
| 98 | 108 | $this->start_controls_section( |
| 99 | 109 | 'kng_facet_price_section', |
| 100 | 110 | [ |
| 101 | - 'label' => KING_ADDONS_ELEMENTOR_ICON . esc_html__('Facet Price', 'king-addons'), | |
| 111 | + 'label' => KING_ADDONS_ELEMENTOR_ICON . esc_html__('Price Filter', 'king-addons'), | |
| 102 | 112 | 'tab' => Controls_Manager::TAB_CONTENT, |
| 103 | 113 | ] |
| 104 | 114 | ); |
| 105 | 115 | |
| @@ -105,11 +115,12 @@ | ||
| 105 | 115 | |
| 106 | 116 | $this->add_control( |
| 107 | 117 | 'kng_filters_query_id', |
| 108 | 118 | [ |
| 109 | - 'label' => esc_html__('Filter Query ID', 'king-addons'), | |
| 119 | + 'label' => esc_html__('Shop Filters ID', 'king-addons'), | |
| 110 | 120 | 'type' => Controls_Manager::TEXT, |
| 111 | 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'), | |
| 112 | 123 | ] |
| 113 | 124 | ); |
| 114 | 125 | |
| 115 | 126 | $this->add_control( |
| @@ -139,9 +150,27 @@ | ||
| 139 | 150 | 'min' => 0.1, |
| 140 | 151 | ] |
| 141 | 152 | ); |
| 142 | 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 | + | |
| 143 | 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); | |
| 144 | 173 | } |
| 145 | 174 | |
| 146 | 175 | /** |
| 147 | 176 | * Render widget output. |
| @@ -159,12 +188,13 @@ | ||
| 159 | 188 | |
| 160 | 189 | $min = isset($settings['kng_min_value']) ? (float) $settings['kng_min_value'] : 0; |
| 161 | 190 | $max = isset($settings['kng_max_value']) ? (float) $settings['kng_max_value'] : 0; |
| 162 | 191 | $step = isset($settings['kng_step']) ? (float) $settings['kng_step'] : 1; |
| 192 | + $variable_price = (($settings['kng_variable_price'] ?? 'any') === 'displayed') ? 'displayed' : 'any'; | |
| 163 | 193 | $show_buckets = true; |
| 164 | 194 | |
| 165 | 195 | ?> |
| 166 | - <div class="king-addons-facet king-addons-facet--price" data-ka-filters-query-id="<?php echo esc_attr($query_id); ?>"> | |
| 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); ?>"> | |
| 167 | 197 | <div class="king-addons-facet__row"> |
| 168 | 198 | <label class="king-addons-facet__label"> |
| 169 | 199 | <?php echo esc_html__('Min', 'king-addons'); ?> |
| 170 | 200 | <input |
| @@ -203,10 +233,17 @@ | ||
| 203 | 233 | ['min' => 250, 'max' => 999999], |
| 204 | 234 | ], |
| 205 | 235 | 'woo_products_grid' |
| 206 | 236 | ); |
| 207 | - foreach ($buckets as $idx => $bucket) : | |
| 208 | - $label = sprintf('%s - %s', wc_price($bucket['min']), wc_price($bucket['max'])); | |
| 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 | + } | |
| 209 | 246 | ?> |
| 210 | 247 | <li class="king-addons-facet__bucket"> |
| 211 | 248 | <button |
| 212 | 249 | type="button" |
| @@ -212,15 +249,15 @@ | ||
| 212 | 249 | type="button" |
| 213 | 250 | class="king-addons-facet__bucket-btn" |
| 214 | 251 | data-ka-filter-type="price-bucket" |
| 215 | 252 | data-ka-filters-query-id="<?php echo esc_attr($query_id); ?>" |
| 216 | - data-ka-price-bucket="<?php echo esc_attr((string) $idx); ?>" | |
| 217 | - data-ka-price-min="<?php echo esc_attr($bucket['min']); ?>" | |
| 218 | - data-ka-price-max="<?php echo esc_attr($bucket['max']); ?>" | |
| 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); ?>" | |
| 219 | 256 | data-ka-price-label="<?php echo esc_attr(wp_strip_all_tags($label)); ?>" |
| 220 | 257 | > |
| 221 | 258 | <span class="king-addons-facet__bucket-label"><?php echo wp_kses_post($label); ?></span> |
| 222 | - <span class="king-addons-facet__bucket-count" data-ka-price-bucket="<?php echo esc_attr((string) $idx); ?>"></span> | |
| 259 | + <span class="king-addons-facet__bucket-count" data-ka-price-bucket="<?php echo esc_attr($bucket_key); ?>"></span> | |
| 223 | 260 | </button> |
| 224 | 261 | </li> |
| 225 | 262 | <?php endforeach; ?> |
| 226 | 263 | </ul> |