Plugin Directory

Changeset 3331383


Ignore:
Timestamp:
07/21/2025 11:03:20 AM (8 months ago)
Author:
simonefontana
Message:

Update plugin version 2.0

Location:
sf-autosuggest-product-search
Files:
41 added
6 edited

Legend:

Unmodified
Added
Removed
  • sf-autosuggest-product-search/trunk/README.txt

    r3207458 r3331383  
    44Requires at least: 3.8.8
    55Requires PHP: 7.0
    6 Tested up to: 6.7
    7 Stable tag: 1.7
     6Tested up to: 6.8
     7Stable tag: 2.0
    88License: GPLv3
    99License URI: http://www.gnu.org/licenses/gpl-3.0.txt
     
    5252Yes, you can search for product taxonomies.
    5353
     54=Can I search products by ACF fields?=
     55Yes, you can search products by ACF fields.
     56
    5457== Screenshots ==
    5558
     
    5861
    5962== Changelog ==
     63= 2.0 =
     64* Added the ability to filter by acf fields
     65* New Admin panel
     66
    6067= 1.7 =
    6168* Added the ability to filter results page
  • sf-autosuggest-product-search/trunk/assets/css/sf_pa_admin.css

    r3015788 r3331383  
    8080}
    8181
     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
    82100
    83101@media all and (max-width: 1100px){
  • sf-autosuggest-product-search/trunk/assets/js/sf_pa_admin.js

    r3027301 r3331383  
    1111           
    1212    });
     13    //Use Woocomerce multiselect in admin
     14    $(".sf_pa-multiselect").selectWoo();
    1315});
  • sf-autosuggest-product-search/trunk/classes/AdminClass.php

    r3170602 r3331383  
    1818   
    1919    public function render_plugin_settings() {
     20        $appearance = false;
     21        if(isset($_GET['tab']) && $_GET['tab'] == 'appearance'){
     22            $appearance = true;
     23        }
    2024        ?>
    2125        <div class="sf_pa-be-container">
     
    2327            <div class="sf_pa_shortcode-banner">
    2428                <?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>
    2533            </div>
    2634            <div class="sf_pa-row">
     
    4856
    4957    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        }
    5064        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>') );
    5267   
    5368        $fields_array = array(
    5469                            array(
    5570                                'title' => __('Search results count', 'sf_products_autosuggest'),
    56                                 'section' => 'sf_pa_apparance',
     71                                'section' => 'sf_pa_settings',
    5772                                'key' => 'results_count',
    5873                                'input' => 'text_input',
     
    6984                            array(
    7085                                'title' => __('Text "Show all results"', 'sf_products_autosuggest'),
    71                                 'section' => 'sf_pa_apparance',
     86                                'section' => 'sf_pa_settings',
    7287                                'key' => 'all_text',
    7388                                'input' => 'text_input',
     
    97112                            array(
    98113                                'title' => __('Show thumbnails', 'sf_products_autosuggest'),
    99                                 'section' => 'sf_pa_apparance',
     114                                'section' => 'sf_pa_settings',
    100115                                'key' => 'show_thumbnail',
    101116                                'input' => 'checkbox',
     
    104119                            array(
    105120                                'title' => __('Show categories', 'sf_products_autosuggest'),
    106                                 'section' => 'sf_pa_apparance',
     121                                'section' => 'sf_pa_settings',
    107122                                'key' => 'show_cat',
    108123                                'input' => 'checkbox',
     
    111126                            array(
    112127                                'title' => __('Show Price', 'sf_products_autosuggest'),
    113                                 'section' => 'sf_pa_apparance',
     128                                'section' => 'sf_pa_settings',
    114129                                'key' => 'show_price',
    115130                                'input' => 'checkbox',
     
    118133                            array(
    119134                                'title' => __('Exclude categories from search', 'sf_products_autosuggest'),
    120                                 'section' => 'sf_pa_apparance',
     135                                'section' => 'sf_pa_settings',
    121136                                'key' => 'exclude_cat',
    122137                                'input' => 'text_input',
     
    125140                            array(
    126141                                'title' => __('Exclude products from search', 'sf_products_autosuggest'),
    127                                 'section' => 'sf_pa_apparance',
     142                                'section' => 'sf_pa_settings',
    128143                                'key' => 'exclude_ids',
    129144                                'input' => 'text_input',
     
    132147                            array(
    133148                                'title' => __('Search for taxonomies', 'sf_products_autosuggest'),
    134                                 'section' => 'sf_pa_apparance',
     149                                'section' => 'sf_pa_settings',
    135150                                'key' => 'taxonomies_search',
    136151                                'input' => 'taxonomies',
     
    138153                            ),
    139154                            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(
    140162                                'title' => __('Stop Words', 'sf_products_autosuggest'),
    141                                 'section' => 'sf_pa_apparance',
     163                                'section' => 'sf_pa_settings',
    142164                                'key' => 'stop_words',
    143165                                'input' => 'textarea',
     
    146168                            array(
    147169                                'title' => __('Use same filter in Results page', 'sf_products_autosuggest'),
    148                                 'section' => 'sf_pa_apparance',
     170                                'section' => 'sf_pa_settings',
    149171                                'key' => 'filter_in_results_page',
    150172                                'input' => 'checkbox',
     
    221243
    222244        $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">
    224246                    <option value="">-- None --</option>';
    225247        foreach($taxonomies as $taxonomy){
     
    233255        }
    234256
     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       
    235299        $html .= '</select>';
    236300        echo $html;
     
    261325        $newinput['exclude_ids'] =  $validator->ids($input['exclude_ids']);
    262326        $newinput['taxonomies_search'] = array();
     327       
    263328        if(isset($input['taxonomies_search']) && !empty($input['taxonomies_search'])){
    264329            foreach($input['taxonomies_search'] as $single_tax){
    265330                if( $single_tax != '')
    266331                    $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);
    267339            }
    268340        }
     
    290362    }
    291363
    292     function create_block_sf_search_block() {
     364    public function create_block_sf_search_block() {
    293365        register_block_type( dirname(__FILE__) . '/../build' );
    294366    }
  • sf-autosuggest-product-search/trunk/classes/SearchClass.php

    r3170602 r3331383  
    3737            }
    3838
    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();
    4041            $join = '';
    4142            $where = '';
     
    4647                $join = " LEFT JOIN ".$wpdb->prefix."icl_translations ON ".$wpdb->prefix."icl_translations.element_id = ".$wpdb->prefix."posts.ID AND element_type = 'post_product'";
    4748                $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);
    5080
    5181            // TODO: Join only if entity checkbox is true
     
    5989                    LEFT JOIN ".$wpdb->prefix."term_taxonomy ON ".$wpdb->prefix."term_taxonomy.term_id = ".$wpdb->prefix."terms.term_id
    6090                    ".$join."
    61                     WHERE ".$wpdb->prefix."posts.post_title 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'
    6292                    AND ".$wpdb->prefix."term_taxonomy.taxonomy = 'product_cat'". $where;
    6393                   
     
    79109
    80110            $prepare[] = $this->count;
    81            
     111
    82112            $results_prod = $wpdb->get_results($wpdb->prepare($sql, $prepare));
    83113
     
    86116                $results_cat = $this->get_taxonomies_search($sf_pa_search);
    87117            }
    88            
    89118
    90119            foreach($results_prod as $single_prod){
     
    191220       
    192221    }
     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    }
    193229}
  • sf-autosuggest-product-search/trunk/sf_products_autosuggest.php

    r3207458 r3331383  
    33* Plugin Name: SF Autosuggest Product Search
    44* Description: Autosuggest Product Search for Woocommerce
    5 * Version: 1.7
     5* Version: 2.0
    66* Author: Simone Fontana
    77* Author URI: https://www.simonefontana.net/
    88* WC requires at least: 3.0.0
    9 * WC tested up to: 9.4
     9* WC tested up to: 10.0
    1010**/
    1111
     
    3838    wp_enqueue_script( 'sf_pa_admin-js', untrailingslashit( plugin_dir_url( __FILE__ ) ).'/assets/js/sf_pa_admin.js', array('jquery'), false, true);
    3939    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');
    4042}
    4143add_action('admin_enqueue_scripts', 'sf_pa_add_admin_scripts');
Note: See TracChangeset for help on using the changeset viewer.