Changeset 3331383
- Timestamp:
- 07/21/2025 11:03:20 AM (8 months ago)
- Location:
- sf-autosuggest-product-search
- Files:
-
- 41 added
- 6 edited
-
tags/2.0 (added)
-
tags/2.0/README.txt (added)
-
tags/2.0/assets (added)
-
tags/2.0/assets/css (added)
-
tags/2.0/assets/css/sf_pa.css (added)
-
tags/2.0/assets/css/sf_pa_admin.css (added)
-
tags/2.0/assets/fonts (added)
-
tags/2.0/assets/fonts/Roboto (added)
-
tags/2.0/assets/fonts/Roboto/LICENSE.txt (added)
-
tags/2.0/assets/fonts/Roboto/Roboto-Black.ttf (added)
-
tags/2.0/assets/fonts/Roboto/Roboto-BlackItalic.ttf (added)
-
tags/2.0/assets/fonts/Roboto/Roboto-Bold.ttf (added)
-
tags/2.0/assets/fonts/Roboto/Roboto-BoldItalic.ttf (added)
-
tags/2.0/assets/fonts/Roboto/Roboto-Italic.ttf (added)
-
tags/2.0/assets/fonts/Roboto/Roboto-Light.ttf (added)
-
tags/2.0/assets/fonts/Roboto/Roboto-LightItalic.ttf (added)
-
tags/2.0/assets/fonts/Roboto/Roboto-Medium.ttf (added)
-
tags/2.0/assets/fonts/Roboto/Roboto-MediumItalic.ttf (added)
-
tags/2.0/assets/fonts/Roboto/Roboto-Regular.ttf (added)
-
tags/2.0/assets/fonts/Roboto/Roboto-Thin.ttf (added)
-
tags/2.0/assets/fonts/Roboto/Roboto-ThinItalic.ttf (added)
-
tags/2.0/assets/img (added)
-
tags/2.0/assets/img/loading.gif (added)
-
tags/2.0/assets/img/search-example.png (added)
-
tags/2.0/assets/js (added)
-
tags/2.0/assets/js/sf_pa.js (added)
-
tags/2.0/assets/js/sf_pa_admin.js (added)
-
tags/2.0/build (added)
-
tags/2.0/build/block.json (added)
-
tags/2.0/build/index.asset.php (added)
-
tags/2.0/build/index.css (added)
-
tags/2.0/build/index.js (added)
-
tags/2.0/build/style-index.css (added)
-
tags/2.0/classes (added)
-
tags/2.0/classes/AdminClass.php (added)
-
tags/2.0/classes/FeedbackClass.php (added)
-
tags/2.0/classes/ResultsPageClass.php (added)
-
tags/2.0/classes/SearchClass.php (added)
-
tags/2.0/classes/ValidatorClass.php (added)
-
tags/2.0/sf_products_autosuggest.php (added)
-
tags/2.0/uninstall.php (added)
-
trunk/README.txt (modified) (3 diffs)
-
trunk/assets/css/sf_pa_admin.css (modified) (1 diff)
-
trunk/assets/js/sf_pa_admin.js (modified) (1 diff)
-
trunk/classes/AdminClass.php (modified) (16 diffs)
-
trunk/classes/SearchClass.php (modified) (6 diffs)
-
trunk/sf_products_autosuggest.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sf-autosuggest-product-search/trunk/README.txt
r3207458 r3331383 4 4 Requires at least: 3.8.8 5 5 Requires PHP: 7.0 6 Tested up to: 6. 77 Stable tag: 1.76 Tested up to: 6.8 7 Stable tag: 2.0 8 8 License: GPLv3 9 9 License URI: http://www.gnu.org/licenses/gpl-3.0.txt … … 52 52 Yes, you can search for product taxonomies. 53 53 54 =Can I search products by ACF fields?= 55 Yes, you can search products by ACF fields. 56 54 57 == Screenshots == 55 58 … … 58 61 59 62 == Changelog == 63 = 2.0 = 64 * Added the ability to filter by acf fields 65 * New Admin panel 66 60 67 = 1.7 = 61 68 * Added the ability to filter results page -
sf-autosuggest-product-search/trunk/assets/css/sf_pa_admin.css
r3015788 r3331383 80 80 } 81 81 82 .sf_pa_none { 83 display: none; 84 } 85 86 .sf_pa_tab_container { 87 display: block; 88 overflow: hidden; 89 margin: 20px 0; 90 border-bottom: 1px solid #dcdcde; 91 } 92 93 .sf_pa_tab_container .nav-tab { 94 font-size: 16px; 95 padding: 10px; 96 border-top-left-radius: 10px; 97 border-top-right-radius: 10px; 98 } 99 82 100 83 101 @media all and (max-width: 1100px){ -
sf-autosuggest-product-search/trunk/assets/js/sf_pa_admin.js
r3027301 r3331383 11 11 12 12 }); 13 //Use Woocomerce multiselect in admin 14 $(".sf_pa-multiselect").selectWoo(); 13 15 }); -
sf-autosuggest-product-search/trunk/classes/AdminClass.php
r3170602 r3331383 18 18 19 19 public function render_plugin_settings() { 20 $appearance = false; 21 if(isset($_GET['tab']) && $_GET['tab'] == 'appearance'){ 22 $appearance = true; 23 } 20 24 ?> 21 25 <div class="sf_pa-be-container"> … … 23 27 <div class="sf_pa_shortcode-banner"> 24 28 <?php _e('To show input use this shortcode: <strong>[sf_pa_search]</strong>', 'sf_products_autosuggest'); ?> 29 </div> 30 <div class="sf_pa_tab_container"> 31 <a href="?page=sf_pa-autosuggest-plugin" class="nav-tab <?php if(!$appearance): ?>nav-tab-active<?php endif; ?>"><?php _e('Settings', 'sf_products_autosuggest'); ?></a> 32 <a href="?page=sf_pa-autosuggest-plugin&tab=appearance" class="nav-tab <?php if($appearance): ?>nav-tab-active<?php endif; ?>"><?php _e('Appearance', 'sf_products_autosuggest'); ?></a> 25 33 </div> 26 34 <div class="sf_pa-row"> … … 48 56 49 57 public function register_settings() { 58 $settings_section = ''; 59 $appearance_section = 'sf_pa_none'; 60 if(isset($_GET['tab']) && $_GET['tab'] == 'appearance'){ 61 $settings_section = 'sf_pa_none'; 62 $appearance_section = ''; 63 } 50 64 register_setting( 'sf_pa_autosuggest_plugin_options', 'sf_pa_autosuggest_plugin_options', [$this, 'plugin_options_validate'] ); 51 add_settings_section( 'sf_pa_apparance', __('Customize search input and autosuggest results', 'sf_products_autosuggest'), [$this, 'apparance_intro'], 'sf_pa_autosuggest_plugin' ); 65 add_settings_section( 'sf_pa_settings', __('Customize search input and autosuggest results', 'sf_products_autosuggest'), [$this, 'apparance_intro'], 'sf_pa_autosuggest_plugin', array('before_section' => '<div id="sf_pa_settings_tab" class="'.$settings_section.'">', 'after_section' => '</div>') ); 66 add_settings_section( 'sf_pa_apparance', __('Customize search input and autosuggest results', 'sf_products_autosuggest'), [$this, 'apparance_intro'], 'sf_pa_autosuggest_plugin', array('before_section' => '<div id="sf_pa_appearance_tab" class="'.$appearance_section.'">', 'after_section' => '</div>') ); 52 67 53 68 $fields_array = array( 54 69 array( 55 70 'title' => __('Search results count', 'sf_products_autosuggest'), 56 'section' => 'sf_pa_ apparance',71 'section' => 'sf_pa_settings', 57 72 'key' => 'results_count', 58 73 'input' => 'text_input', … … 69 84 array( 70 85 'title' => __('Text "Show all results"', 'sf_products_autosuggest'), 71 'section' => 'sf_pa_ apparance',86 'section' => 'sf_pa_settings', 72 87 'key' => 'all_text', 73 88 'input' => 'text_input', … … 97 112 array( 98 113 'title' => __('Show thumbnails', 'sf_products_autosuggest'), 99 'section' => 'sf_pa_ apparance',114 'section' => 'sf_pa_settings', 100 115 'key' => 'show_thumbnail', 101 116 'input' => 'checkbox', … … 104 119 array( 105 120 'title' => __('Show categories', 'sf_products_autosuggest'), 106 'section' => 'sf_pa_ apparance',121 'section' => 'sf_pa_settings', 107 122 'key' => 'show_cat', 108 123 'input' => 'checkbox', … … 111 126 array( 112 127 'title' => __('Show Price', 'sf_products_autosuggest'), 113 'section' => 'sf_pa_ apparance',128 'section' => 'sf_pa_settings', 114 129 'key' => 'show_price', 115 130 'input' => 'checkbox', … … 118 133 array( 119 134 'title' => __('Exclude categories from search', 'sf_products_autosuggest'), 120 'section' => 'sf_pa_ apparance',135 'section' => 'sf_pa_settings', 121 136 'key' => 'exclude_cat', 122 137 'input' => 'text_input', … … 125 140 array( 126 141 'title' => __('Exclude products from search', 'sf_products_autosuggest'), 127 'section' => 'sf_pa_ apparance',142 'section' => 'sf_pa_settings', 128 143 'key' => 'exclude_ids', 129 144 'input' => 'text_input', … … 132 147 array( 133 148 'title' => __('Search for taxonomies', 'sf_products_autosuggest'), 134 'section' => 'sf_pa_ apparance',149 'section' => 'sf_pa_settings', 135 150 'key' => 'taxonomies_search', 136 151 'input' => 'taxonomies', … … 138 153 ), 139 154 array( 155 'title' => __('Search for Acf Fields', 'sf_products_autosuggest'), 156 'section' => 'sf_pa_settings', 157 'key' => 'acf_fields_search', 158 'input' => 'acf_fields', 159 'instruction' => __('Select wich Acf Fields want search.', 'sf_products_autosuggest') 160 ), 161 array( 140 162 'title' => __('Stop Words', 'sf_products_autosuggest'), 141 'section' => 'sf_pa_ apparance',163 'section' => 'sf_pa_settings', 142 164 'key' => 'stop_words', 143 165 'input' => 'textarea', … … 146 168 array( 147 169 'title' => __('Use same filter in Results page', 'sf_products_autosuggest'), 148 'section' => 'sf_pa_ apparance',170 'section' => 'sf_pa_settings', 149 171 'key' => 'filter_in_results_page', 150 172 'input' => 'checkbox', … … 221 243 222 244 $taxonomies = get_object_taxonomies('product','objects'); 223 $html = '<select name="sf_pa_autosuggest_plugin_options['.$params["key"].'][]" multiple="multiple">245 $html = '<select class="sf_pa-multiselect" name="sf_pa_autosuggest_plugin_options['.$params["key"].'][]" multiple="multiple"> 224 246 <option value="">-- None --</option>'; 225 247 foreach($taxonomies as $taxonomy){ … … 233 255 } 234 256 257 $html .= '</select>'; 258 echo $html; 259 } 260 261 public function acf_fields($params){ 262 $options = get_option( 'sf_pa_autosuggest_plugin_options' ); 263 264 $html = '<select class="sf_pa-multiselect" name="sf_pa_autosuggest_plugin_options['.$params["key"].'][]" multiple="multiple"> 265 <option value="">-- None --</option>'; 266 267 if(function_exists('acf_get_field_groups')){ 268 $groups = acf_get_field_groups(array('post_type' => 'product')); 269 foreach($groups as $group){ 270 271 if(isset($group['key'])){ 272 foreach(acf_get_fields($group['key']) as $field){ 273 //Remove acf repeater and acf true/false 274 if(isset($field['type']) && $field['type'] != 'repeater' && $field['type'] != 'true_false'){ 275 //TODO: dynamize sub_fields and active also for repeater 276 if($field['type'] == 'group'){ 277 foreach($field['sub_fields'] as $subfield){ 278 $selected = ''; 279 if(isset($options[$params['key']]) && in_array($field['name'].'_'.$subfield['name'], $options[$params['key']])){ 280 $selected = 'selected'; 281 } 282 $html .= '<option value="'.$field['name'].'_'.$subfield['name'].'" '.$selected.'>'.$subfield['label'].'<br>'; 283 } 284 } 285 else{ 286 $selected = ''; 287 if(isset($options[$params['key']]) && in_array($field['name'], $options[$params['key']])){ 288 $selected = 'selected'; 289 } 290 $html .= '<option value="'.$field['name'].'" '.$selected.'>'.$field['label'].'<br>'; 291 } 292 } 293 } 294 } 295 296 } 297 } 298 235 299 $html .= '</select>'; 236 300 echo $html; … … 261 325 $newinput['exclude_ids'] = $validator->ids($input['exclude_ids']); 262 326 $newinput['taxonomies_search'] = array(); 327 263 328 if(isset($input['taxonomies_search']) && !empty($input['taxonomies_search'])){ 264 329 foreach($input['taxonomies_search'] as $single_tax){ 265 330 if( $single_tax != '') 266 331 $newinput['taxonomies_search'][] = $validator->plaintext($single_tax); 332 } 333 } 334 335 if(isset($input['acf_fields_search']) && !empty($input['acf_fields_search'])){ 336 foreach($input['acf_fields_search'] as $single_acf){ 337 if( $single_acf!= '') 338 $newinput['acf_fields_search'][] = $validator->plaintext($single_acf); 267 339 } 268 340 } … … 290 362 } 291 363 292 function create_block_sf_search_block() {364 public function create_block_sf_search_block() { 293 365 register_block_type( dirname(__FILE__) . '/../build' ); 294 366 } -
sf-autosuggest-product-search/trunk/classes/SearchClass.php
r3170602 r3331383 37 37 } 38 38 39 $prepare = array($this->options['show_cat'], $this->options['show_thumbnail'], $this->options['show_price'], '%' . $wpdb->esc_like($sf_pa_search) .'%'); 39 $prepare_join = array($this->options['show_cat'], $this->options['show_thumbnail'], $this->options['show_price']); 40 $prepare_where = array(); 40 41 $join = ''; 41 42 $where = ''; … … 46 47 $join = " LEFT JOIN ".$wpdb->prefix."icl_translations ON ".$wpdb->prefix."icl_translations.element_id = ".$wpdb->prefix."posts.ID AND element_type = 'post_product'"; 47 48 $where = " AND ".$wpdb->prefix."icl_translations.language_code = %s"; 48 $prepare[] = $lang; 49 } 49 $prepare_where[] = $lang; 50 } 51 52 //If acf search active add Where clause 53 if(isset($this->options['acf_fields_search']) && !empty($this->options['acf_fields_search']) && is_array($this->options['acf_fields_search'])){ 54 $acf_fields = $this->get_acf_fields_search(); 55 if($acf_fields){ 56 $placeholder_in = ''; 57 $count_acf = count($acf_fields); 58 foreach($acf_fields as $key => $single_field){ 59 if($count_acf != $key + 1){ 60 $placeholder_in .= '%s, '; 61 } 62 else{ 63 $placeholder_in .= '%s'; 64 } 65 $prepare_join[] = $single_field; 66 } 67 $join .= " LEFT JOIN ".$wpdb->prefix."postmeta as acf_postmeta ON acf_postmeta.post_id = ".$wpdb->prefix."posts.ID AND acf_postmeta.meta_key IN (".$placeholder_in.")"; 68 $where .= " AND (".$wpdb->prefix."posts.post_title LIKE %s OR acf_postmeta.meta_value LIKE %s)"; 69 $prepare_where[] = '%' . $wpdb->esc_like($sf_pa_search) .'%'; 70 $prepare_where[] = '%' . $wpdb->esc_like($sf_pa_search) .'%'; 71 } 72 73 } 74 else{ 75 $where .= ' AND '.$wpdb->prefix.'posts.post_title LIKE %s'; 76 $prepare_where[] = '%' . $wpdb->esc_like($sf_pa_search) .'%'; 77 } 78 79 $prepare = array_merge($prepare_join, $prepare_where); 50 80 51 81 // TODO: Join only if entity checkbox is true … … 59 89 LEFT JOIN ".$wpdb->prefix."term_taxonomy ON ".$wpdb->prefix."term_taxonomy.term_id = ".$wpdb->prefix."terms.term_id 60 90 ".$join." 61 WHERE ".$wpdb->prefix."posts.post_t itle LIKE %s AND ".$wpdb->prefix."posts.post_type = 'product' AND ".$wpdb->prefix."posts.post_status = 'publish'91 WHERE ".$wpdb->prefix."posts.post_type = 'product' AND ".$wpdb->prefix."posts.post_status = 'publish' 62 92 AND ".$wpdb->prefix."term_taxonomy.taxonomy = 'product_cat'". $where; 63 93 … … 79 109 80 110 $prepare[] = $this->count; 81 111 82 112 $results_prod = $wpdb->get_results($wpdb->prepare($sql, $prepare)); 83 113 … … 86 116 $results_cat = $this->get_taxonomies_search($sf_pa_search); 87 117 } 88 89 118 90 119 foreach($results_prod as $single_prod){ … … 191 220 192 221 } 222 223 private function get_acf_fields_search(){ 224 if(is_array($this->options['acf_fields_search']) && !empty($this->options['acf_fields_search'])) 225 return $this->options['acf_fields_search']; 226 227 return false; 228 } 193 229 } -
sf-autosuggest-product-search/trunk/sf_products_autosuggest.php
r3207458 r3331383 3 3 * Plugin Name: SF Autosuggest Product Search 4 4 * Description: Autosuggest Product Search for Woocommerce 5 * Version: 1.75 * Version: 2.0 6 6 * Author: Simone Fontana 7 7 * Author URI: https://www.simonefontana.net/ 8 8 * WC requires at least: 3.0.0 9 * WC tested up to: 9.49 * WC tested up to: 10.0 10 10 **/ 11 11 … … 38 38 wp_enqueue_script( 'sf_pa_admin-js', untrailingslashit( plugin_dir_url( __FILE__ ) ).'/assets/js/sf_pa_admin.js', array('jquery'), false, true); 39 39 wp_enqueue_style('sf_pa_admin-css', untrailingslashit( plugin_dir_url( __FILE__ ) ).'/assets/css/sf_pa_admin.css'); 40 wp_enqueue_style('woocommerce_admin_styles'); 41 wp_enqueue_script('selectWoo'); 40 42 } 41 43 add_action('admin_enqueue_scripts', 'sf_pa_add_admin_scripts');
Note: See TracChangeset
for help on using the changeset viewer.