GET FREE VERSION GET THE PRO VERSION

Hooks Reference

List of the plugin php hooks.

HookTypeDescription
aws_meta_keysfilterAdmin hook. Final array of meta fields for the settings page.
aws_meta_keys_includefilterAdmin hook. Add to the array of meta fields additional fields.
aws_meta_keys_unfilteredfilterAdmin hook. Array of meta fields for the settings page before filtering.
aws_admin_page_optionsfilterAdmin hook. Filter options array for the plugin settings page.
aws_before_strip_shortcodesfilterIndex table hook. Filter product strings before stripping shortcodes.
aws_special_charsfilterSpecial characters to remove from the product strings.
aws_diacritic_charsfilterFilters array of diacritic chars.
aws_normalize_stringfilterFilters products normalized strings.
aws_synonyms_option_arrayfilterFilters synonyms array before adding them to the index table.
aws_front_filtersfilterArray of search form filters before output.
aws_front_data_parametersfilterFilter search form settings.
aws_searchbox_markupfilterFilter search form HTML output.
aws_search_page_filtersfilterActive products filters of current search results page.
aws_products_search_page_filteredfilterProduct on search results page after filters apply.
aws_products_order_byfilterFilter order by value for search results page.
aws_products_orderfilterProduct on search results page after the ordering.
aws_index_posts_per_pagefilterIndex table hook. Number of products to be indexed per iteration.
aws_index_cron_runner_time_limitfilterIndex table hook. Maximum execution time for the index script.
aws_index_max_cron_attempsfilterIndex table hook. Max number of the index script repeats before failing.
aws_index_product_idsfilterIndex table hook. Array of products IDs that will be indexed.
aws_index_apply_filtersfilterIndex table hook. Apply or not standard content filters for indexed data.
aws_indexed_titlefilterIndex table hook. Filters product title before it will be indexed.
aws_indexed_contentfilterIndex table hook. Filters product content before it will be indexed.
aws_indexed_excerptfilterIndex table hook. Filters product short description before it will be indexed.
aws_indexed_custom_fieldsfilterIndex table hook. Filters product custom fields before they will be indexed.
aws_indexed_datafilterIndex table hook. Filters product data before adding to the index table.
aws_create_index_table_sqlfilterIndex table hook. Filters SQL query that will be using to create index table.
aws_extracted_stringfilterIndex table hook. Filters extracted from the product data strings before index.
aws_extracted_termsfilterIndex table hook. Filters array of product terms before index.
aws_page_resultsfilterTotal number of search results for search results page.
aws_posts_per_pagefilterNumber of search results per page for search results page.
aws_searchpage_enabledfilterDisplay or not plugin results for current search results page.
aws_search_page_resultsfilterArray of results for search results page.
aws_search_page_queryfilterSearch query string for search results page.
aws_search_results_products_idsfilterArray of product IDs to display as search results.
aws_search_results_productsfilterFilter products search results.
aws_search_results_tax_archivesfilterList of enabled for search taxonomies archive pages.
aws_search_results_allfilterFilter all search results before displaying.
aws_search_termsfilterFilters array of search terms before generating SQL query.
aws_tax_filter_include_childsfilterInclude or not child terms for taxonomies filter.
aws_exclude_productsfilterExclude certain products from the search results.
aws_search_current_langfilterProducts language to search for.
aws_search_query_arrayfilterFilter search query parameters.
aws_search_query_stringfilterFilter search query SQL string.
aws_title_search_resultfilterProduct title inside search results list.
aws_excerpt_search_resultfilterProduct excerpt inside search results list.
aws_search_pre_filter_productsfilterFilter products array before the output.
aws_image_sizefilterSize of product images inside search results block.
aws_highlight_tagfilterTag to use for highlighting search words inside the content.
aws_tax_search_datafilterFilters the array of taxonomies search data.
aws_search_terms_numberfilterMaximal number of taxonomies archive pages inside search results.
aws_terms_search_queryfilterFilter taxonomies archive pages SQL query string.
aws_search_tax_resultsfilterFilter taxonomies archive pages results.
aws_search_terms_descriptionfilterSearch or not inside the taxonomy terms description.
aws_search_tax_excludefilterExclude certain taxonomies terms from the search results.
aws_terms_exclude_$taxonomy_namefilterExclude certain terms archive pages from the search results.
aws_users_search_datafilterFilters the array of users search data.
aws_users_search_argsfilterFilter users search query arguments.
aws_users_search_queryfilterFilter users archive pages SQL query string.
aws_search_users_resultsfilterFilter user archive pages results.
aws_js_seamless_selectorsfilterSelectors for search form js replacement.
aws_js_seamless_form_idfilterForm that will be used for JS seamless integration.
aws_js_seamless_searchbox_markupfilterFilter seamless integrations default form markup.
aws_search_startactionFires each time when performing the search.
aws_cache_clearactionFires each time when the plugin cache was cleared.
aws_form_changedactionFires after the search form instance was created/copied/deleted.
aws_filters_changedactionFires after the search form filter was created/copied/deleted.
aws_settings_savedactionFires after the plugin settings were saved.
aws_create_index_tableactionFires when the plugin index table is created.
aws_index_completeactionFires once the index process is complete.

 

aws_meta_keys

apply_filters( 'aws_meta_keys', (array) $meta_keys );

Admin hook. Final array of meta fields for the settings page. Contains meta fields that can be enabled for search.

Changelog

  • Added in version 1.32

Parameters

  • $meta_keys (array) Array of meta fields

Example

By default inner meta fields ( field names starts with _ ) are not showing inside the plugin settings page. Let's show _kad_tab_ inside the settings page and make it possible to enable search for it.

add_filter( 'aws_meta_keys', 'my_aws_meta_keys' );
function my_aws_meta_keys( $meta_keys ) {
    $meta_slug = '_kad_tab_';
    $meta_name = 'meta_' . strtolower( $meta_slug );
    $meta_keys[$meta_name] = $meta_slug;
    return $meta_keys;
}

 

aws_meta_keys_include

apply_filters( 'aws_meta_keys_include', (array) $include_meta );

Admin hook. Add to the array of meta fields additional fields that are excluded by default.

Changelog

  • Added in version 1.57

Parameters

  • $include_meta (array) Array of additional meta fields

Example

By default inner meta fields ( field names starts with _ ) are not showing inside the plugin settings page. Let's show _product_subtitle and _custom_product_features inside the settings page and make it possible to enable search inside them.

add_filter( 'aws_meta_keys_include', 'my_aws_meta_keys_include' );
function my_aws_meta_keys_include( $include_meta ) {
    $include_meta[] = '_product_subtitle';
    $include_meta[] = '_custom_product_features ';
    return $include_meta;
}

 

aws_meta_keys_unfiltered

apply_filters( 'aws_meta_keys_unfiltered', (array) $meta );

Admin hook. Array of meta fields for the settings page before filtering. Include all inner meta fields ( that name starts with _ ).

Changelog

  • Added in version 2.07

Parameters

  • $meta (array) Array of unfiltered meta fields

Example

Remove meta field aliases from the plugin settings page.

add_filter( 'aws_meta_keys_unfiltered', 'my_aws_meta_keys_unfiltered' );
function my_aws_meta_keys_unfiltered( $meta ) {
    if ( is_array( $meta ) && !empty( $meta ) ) {
        foreach ( $meta as $arr_key => $field ) {
            if ( isset( $field->meta_key ) && $field->meta_key === 'aliases' ) {
                unset( $meta[$arr_key] );
            }
        }
    }
    return $meta;
}

 

aws_admin_page_options

apply_filters( 'aws_admin_page_options', (array) $options );

Admin area hook. Filter options array for the plugin settings page.

Changelog

  • Added in version 2.15

Parameters

  • $options (array) Array of plugin options

Example

Lets add a new option called show_on_mobile. When disable it must hide search form on mobile devices. Note that in this example we only add show_on_mobile option inside the plugin settings page and not create any logic that must hide the search form depending on this option value.

add_filter( 'aws_admin_page_options', 'my_aws_admin_page_options' );
function my_aws_admin_page_options( $options ) {
    $options['general'][] = array(
        "name" => __( "Show on mobile", "advanced-woo-search" ),
        "desc"  => __( "Show or not search form on mobile devices.", "advanced-woo-search" ),
        "id"   => "show_on_mobile",
        "value" => 'true',
        "type"  => "select",
        'choices' => array(
            'true'  => __( 'Show', 'advanced-woo-search' ),
            'false' => __( 'Hide', 'advanced-woo-search' ),
        )
    );
    return $options;
}

 

aws_before_strip_shortcodes

apply_filters( 'aws_before_strip_shortcodes', (string) $str );

Index table hook. Filter product content strings before stripping shortcodes and add content to the plugin index table.

Changelog

  • Added in version 1.92

Parameters

  • $str (string) Product string to index.

Example

We have shortcode [my_shortcode] and want to replace it with some custom value before it will be stripped.

add_filter( 'aws_before_strip_shortcodes', 'my_aws_before_strip_shortcodes' );
function my_aws_before_strip_shortcodes( $str ) {
    $str = str_replace( '[my_shortcode]', 'Custom shortcode contetn', $str );
    return $str;
}

 

aws_special_chars

apply_filters( 'aws_special_chars', (array) $chars );

Special characters to remove from the product strings.

Changelog

  • Added in version 1.00

Parameters

  • $chars (array) Array of special characters.

Example

For example, we have products with strings 21.R31 and 21R31. Plugin default behaviour is to strip . character from the search string. So no matter will the user search for 21.R31 or21R31 - the search results will be the same. But if we want to show different results for these two queries we need to disable the stripping of the dot . characters.

add_filter( 'aws_special_chars', 'my_aws_special_chars' );
function my_aws_special_chars( $chars ) {
    unset( $chars[array_search( '.',$chars )] );
    return $chars;
}

 

aws_diacritic_chars

apply_filters( 'aws_diacritic_chars', (array) $chars );

Filters array of diacritic chars. Array contains pare diacritic char => character to replace with.

Changelog

  • Added in version 1.41

Parameters

  • $chars (array) Array of diacritic characters.

Example

By default if inside out product content we have character ž it will be replaced with z letter. Lets change this and replace character ž with ze.

add_filter( 'aws_diacritic_chars', 'my_aws_diacritic_chars' );
function my_aws_diacritic_chars( $chars ) {
    $chars['ž'] = 'ze';
    return $chars;
}

 

aws_normalize_string

apply_filters( 'aws_normalize_string', (string) $string );

Filters products normalized ( without special characters, html tags and shortcodes ) strings.

Changelog

  • Added in version 1.41

Parameters

  • $string (string) Product normalized content string.

Example

For example we want to search for product SKU numbers. Sometimes these SKUs contain prefix VOE and sometimes. Like VOE123456 or 654321. But we need exact SKU search without looking at this prefix. The best solution here - just remove VOE from the product SKU.

add_filter( 'aws_normalize_string', 'my_aws_normalize_string' );
function my_aws_normalize_string( $string ) {
    $pattern = '/(VOE)+/i';
    $string = preg_replace( $pattern, '', $string );
    return $string;
}

 
Another example - we have two products with strings 21.R31 and 21R31. By default plugin removes special characters like . from the string. So 21.R31 becomes 21R31. But what to do if we enable the exact match search ( available with PRO version ) and search for R31? Default results - empty. But we can replace . with the empty space character, so during the index process 21.R31 becomes 21 R31 and exact match search for R31 will show proper search results.

add_filter( 'aws_normalize_string', 'my_aws_normalize_string' );
function my_aws_normalize_string( $string ) {
    $string = str_replace( '.', ' ', $string );
    return $string;
}

 

aws_synonyms_option_array

apply_filters( 'aws_synonyms_option_array', (array) $synonyms );

Filters synonyms array before adding them to the index table where needed. Contains the same synonyms groups that were specified inside the plugin settings page.

Changelog

  • Added in version 1.70

Parameters

  • $synonyms (array) Array of synonyms.

Example

Lets add new synonyms group box, package, pac. Instead of adding it from the plugin settings page we will use a current filter.

add_filter( 'aws_synonyms_option_array', 'my_aws_synonyms_option_array' );
function my_aws_synonyms_option_array( $synonyms ) {
    $synonyms[] = 'box, package, pac';
    return $synonyms;
}

 

aws_front_filters

apply_filters( 'aws_front_filters', (array) $filters, (int) $form_id );

Array of search form filters before output. Contains filter created via plugin settings page.

Changelog

  • Added in version 1.66

Parameters

  • $filters (array) Array of search form filters.
  • $form_id (int) Form id

Example

Remove the second form filter id if the search form is inside product_cat archive page.

add_filter( 'aws_front_filters', 'my_aws_front_filters', 10, 2 );
function my_aws_front_filters( $filters, $form_id ) {
    if ( is_tax( 'product_cat' ) ) {
        unset( $filters['filters'][1] );
    }
    return $filters;
}

 

aws_front_data_parameters

apply_filters( 'aws_front_data_parameters', (array) $params, (int) $form_id );

Array of search form settings before generate the form.

Changelog

  • Added in version 1.61

Parameters

  • $params (array) Array of search form settings.
  • $form_id (int) Form id

Example

Change SKU word for product search results to ISBN.

add_filter( 'aws_front_data_parameters', 'my_aws_front_data_parameters', 10, 2 );
function my_aws_front_data_parameters( $params, $form_id ) {
    $params['data-sku'] = 'ISBN';
    return $params;
}

 
Disable AJAX search for mobile devices.

add_filter( 'aws_front_data_parameters', 'my_aws_front_data_parameters', 10, 2 );
function my_aws_front_data_parameters( $params ) {
    if ( wp_is_mobile() ) {
        $params['data-show-page'] = 'ajax_off';
    }
    return $params;
}

 

aws_searchbox_markup

apply_filters( 'aws_searchbox_markup', (string) $markup, (array) $params );

Array of search form settings before generating the form.

Changelog

  • Added in version 1.00
  • $params - added in version 1.60

Parameters

  • $markup (string) Search form HTML markup
  • $params (array) Array of search form settings.

Example

Add description Start typing your search words here near search form.

add_filter( 'aws_searchbox_markup', 'my_aws_searchbox_markup', 10, 2 );
function my_aws_searchbox_markup( $markup, $params ) {
    $content = 'Start typing your search words here';
    $form = '<form class="aws-search-form"';
    $markup = str_replace( $form, $content .  $form, $markup );
    return $markup;
}

 
Change search form default magnifier svg icon.

add_filter( 'aws_searchbox_markup', 'my_aws_searchbox_markup', 10, 2 );
function my_aws_searchbox_markup( $markup, $params ) {
    $pattern = '/<svg[Ss]*?</svg>/i';
    $new_icon = '<style>.aws-container .aws-search-form .aws-search-btn_icon{height: 18px;}</style></style><svg aria-hidden="true" data-prefix="fas" data-icon="search" class="svg-inline--fa fa-search fa-w-16" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"> <path fill="currentColor" d="M505 442.7L405.3 343c-4.5-4.5-10.6-7-17-7H372c27.6-35.3 44-79.7 44-128C416 93.1 322.9 0 208 0S0 93.1 0 208s93.1 208 208 208c48.3 0 92.7-16.4 128-44v16.3c0 6.4 2.5 12.5 7 17l99.7 99.7c9.4 9.4 24.6 9.4 33.9 0l28.3-28.3c9.4-9.4 9.4-24.6.1-34zM208 336c-70.7 0-128-57.2-128-128 0-70.7 57.2-128 128-128 70.7 0 128 57.2 128 128 0 70.7-57.2 128-128 128z"></path> </svg>';
    $markup = preg_replace( $pattern, $new_icon, $markup );
    return $markup;
}

 

aws_search_page_filters

apply_filters( 'aws_search_page_filters', (array) $filters );

Active product filter of current search results page. Contains such values like on_sale, price_min, price_max, rating, etc.

Changelog

  • Added in version 2.04

Parameters

  • $filters (array) Array of active search page filters.

Example

If price filters are not active that show only products in price range 0 - 100.

add_filter( 'aws_search_page_filters', 'my_aws_search_page_filters' );
function my_aws_search_page_filters( $filters ) {
    if ( ! isset( $filters['price_max'] ) && ! isset( $filters['price_min'] ) ) {
        $filters['price_max'] = '100';
        $filters['price_min'] = '0';
    }
    return $filters;
}

 

aws_products_search_page_filtered

apply_filters( 'aws_products_search_page_filtered', (array) $products );

Product on search results page after filters apply.

Changelog

  • Added in version 2.04

Parameters

  • $products (array) Array of products.

Example

For the search results page lets remove products with ID 7966.

add_filter( 'aws_products_search_page_filtered', 'my_aws_products_search_page_filtered' );
function my_aws_products_search_page_filtered( $products ) {
    if ( $products && is_array( $products ) ) {
        foreach( $products as $key => $product ) {
            if ( $product['id'] === 7966 ) {
                unset( $products[$key] );
            }
        }
    }
    return $products;
}

 

aws_products_order_by

apply_filters( 'aws_products_order_by', (string) $order_by, (object) $query );

Filter order by value for search results page.

Changelog

  • Added in version 2.13

Parameters

  • $order_by (string) Order by value.
  • $query (object) Page query object.

Example

Change orderby value to price if page default orderby value set to meta_value_num.

add_filter( 'aws_products_order_by', 'my_aws_products_order_by', 10, 2 );
function my_aws_products_order_by( $order_by, $query ) {
    if ( $query->query_vars['orderby'] === 'meta_value_num' ) {
        $order_by = 'price';
    }
    return $order_by;
}

 

aws_products_order

apply_filters( 'aws_products_order', (array) $products, (string) $order_by );

Product on search results page after the ordering.

Changelog

  • Added in version 1.91

Parameters

  • $products (array) Array of products.
  • $order_by (string) Order by value.

Example

For the search results page lets remove products with ID 7966.

add_filter( 'aws_products_order', 'my_aws_products_order', 10, 2 );
function my_aws_products_order( $products, $order_by ) {
    if ( $products && is_array( $products ) ) {
        foreach( $products as $key => $product ) {
            if ( $product['id'] === 7966 ) {
                unset( $products[$key] );
            }
        }
    }
    return $products;
}

 

aws_index_posts_per_page

apply_filters( 'aws_index_posts_per_page', (int) $num );

Index table hook. Number of products to be indexed per one request. Largest number can speed-up the index process but can lead to time-out error.

Changelog

  • Added in version 1.00

Parameters

  • $num (int) Number of product. Default = 20.

Example

Increase the number of products to be indexed per one request to 50.

add_filter( 'aws_index_posts_per_page', 'my_aws_index_posts_per_page' );
function my_aws_index_posts_per_page( $num ) {
    return 50;
}

 

aws_index_cron_runner_time_limit

apply_filters( 'aws_index_cron_runner_time_limit', (int) $num );

Index table hook. Maximum execution time for the cron index script.

Changelog

  • Added in version 1.50

Parameters

  • $num (int) Maximal execution time in seconds. Default = 600.

Example

Increase maximum execution time to 1000.

add_filter( 'aws_index_cron_runner_time_limit', 'my_aws_index_cron_runner_time_limit' );
function my_aws_index_cron_runner_time_limit( $num ) {
    return 1000;
}

 

aws_index_max_cron_attemps

apply_filters( 'aws_index_max_cron_attemps', (int) $num );

Index table hook. Max number of the cron index script repeats before failing.

Changelog

  • Added in version 1.50

Parameters

  • $num (int) Number of cron job repeats . Default = 10.

Example

Decrease number of cron job attempts to 5.

add_filter( 'aws_index_max_cron_attemps', 'my_aws_index_max_cron_attemps' );
function my_aws_index_max_cron_attemps( $num ) {
    return 5;
}

 

aws_index_product_ids

apply_filters( 'aws_index_product_ids', (array) $ids );

Filter the array of product IDs that will be indexed.

Changelog

  • Added in version 1.70

Parameters

  • $ids (array) Array of product IDs.

Example

Remove from the plugin index table products with IDs 8056 and 8036.

add_filter( 'aws_index_product_ids', 'my_aws_index_product_ids' );
function my_aws_index_product_ids( $ids ) {
    unset( $ids[array_search( 8056, $ids )] );
    unset( $ids[array_search( 8036, $ids )] );
    return $ids;
}

 

aws_index_apply_filters

apply_filters( 'aws_index_apply_filters', (bool) $apply );

Apply or not the_content filter to product content before the index. Some additional content can be added via this hook. Enabling can lead to a heavy increase of the plugin index table.

Changelog

  • Added in version 1.73

Parameters

  • $apply (bool) Apply or not content filters.

Example

Enably apply of the_content filter for product content.

add_filter( 'aws_index_apply_filters', 'my_aws_index_apply_filters' );
function my_aws_index_apply_filters( $apply ) {
    return true;
}

 

aws_indexed_title

apply_filters( 'aws_indexed_title', (string) $title, (int) $product_id, (object) $product );

Index table hook. Filters product title before it will be indexed.

Changelog

  • Added in version 1.24

Parameters

  • $title (string) Product title.
  • $product_id (int) Product id.
  • $product (object) Product object.

Example

For example we have a grouped product that has several child products inside. We want to display inside search results this main grouped product when the user searches for one of the child products title or SKU.

add_filter( 'aws_indexed_title', 'my_aws_indexed_title', 10, 3 );
function my_aws_indexed_title( $title, $id, $product ) {
    if ( $product->is_type( 'grouped' ) ) {
        $children = $product->get_children();
        if ( sizeof( $children ) > 0 ) {
            foreach ( $children as $child_id ) {
                $child_product = wc_get_product( $child_id );
                $title .= ' ' . get_the_title( $child_id );
                $title .= ' ' . $child_product->get_sku();
            }
        }
    }
    return $title;
}

 
Some products contain stock_number custom fields. We want to show the corresponding products when users search for this custom field value. This can be achieved by adding stock_number field value to product title for indexing.

add_filter( 'aws_indexed_title', 'my_aws_indexed_title', 10, 3 );
function my_aws_indexed_title( $title, $id, $product ) {
    $stock_number = get_post_meta( $id, 'stock_number', true );
    if ( $stock_number ) {
        $title .= ' ' . $stock_number;
    }
    return $title;
}

 

aws_indexed_content

apply_filters( 'aws_indexed_content', (string) $content, (int) $product_id, (object) $product );

Index table hook. Filters product content before it will be indexed.

Changelog

  • Added in version 1.24

Parameters

  • $content (string) Product content.
  • $product_id (int) Product id.
  • $product (object) Product object.

Example

We have the product with custom fields custom_field. We want to show the corresponding products when users search for this field value. This can be achieved by adding custom_field field value to the product content during the index process.

add_filter( 'aws_indexed_content', 'my_aws_indexed_content', 10, 3 );
function my_aws_indexed_content( $content, $id, $product ) {
    $custom_field = get_post_meta( $id, 'custom_field', true );
    if ( $custom_field ) {
        $content .= ' ' . $custom_field;
    }
    return $content;
}

 

aws_indexed_excerpt

apply_filters( 'aws_indexed_excerpt', (string) $excerpt, (int) $product_id, (object) $product );

Index table hook. Filters product short description before it will be indexed.

Changelog

  • Added in version 1.24

Parameters

  • $excerpt (string) Product short description.
  • $product_id (int) Product id.
  • $product (object) Product object.

Example

If we are not using product short description as a search source then it is possible to fully remove it from the plugin index table. This will decrease index table size and can speed-up search.

add_filter('aws_indexed_excerpt', 'my_aws_indexed_excerpt', 10, 3 );
function my_aws_indexed_excerpt( $excerpt, $id, $product ) {
    return '';
}

 
We have the product with custom fields product_vin_number that contains VIN code of the current product. We want to enable product search via this VIN number. This can be achieved by adding product_vin_number field value to the product short description during the index process.

add_filter( 'aws_indexed_excerpt', 'my_aws_indexed_excerpt', 10, 3 );
function my_aws_indexed_excerpt( $excerpt, $id, $product ) {
    $product_vin_number = get_post_meta( $id, 'product_vin_number', true );
    if ( $product_vin_number ) {
        $excerpt .= ' ' . $product_vin_number;
    }
    return $excerpt;
}

 

aws_indexed_custom_fields

apply_filters( 'aws_indexed_custom_fields', (array) $custom_fields, (int) $product_id, (object) $product );

Index table hook. Filters product custom fields before they will be indexed.

Changelog

  • Added in version 1.54

Parameters

  • $custom_fields (array) Product custom fields array.
  • $product_id (int) Product id.
  • $product (object) Product object.

Example

If we are not using search via product custom fields then it is possible to fully remove them from the plugin index table. This action will decrease index table size and can speed-up search.

add_filter( 'aws_indexed_custom_fields', 'my_aws_indexed_custom_fields', 10, 3 );
function my_aws_indexed_custom_fields( $custom_fields, $product_id, $product ) {
    return '';
}

 

aws_indexed_data

apply_filters( 'aws_indexed_data', (array) $data, (int) $product_id );

Index table hook. Filters product data before adding to the index table.

Changelog

  • Added in version 1.54

Parameters

  • $data (array) Product data array.
  • $product_id (int) Product id.

Example

If we are not using search via product custom fields, taxonomies and attributes then it is possible not to index these data. This action will decrease index table size and can speed-up search.

add_filter( 'aws_indexed_data', 'my_aws_indexed_data', 10, 2 );
function my_aws_indexed_data( $data, $product_id ) {
    foreach ( $data['terms'] as $source => $all_terms ) {
        if ( strpos( $source, 'meta_' ) === 0 || strpos( $source, 'tax_' ) === 0 || strpos( $source, 'attr_' ) === 0 ) {
            unset( $data['terms'][$source] );
        }
    }
    return $data;
}

 
Plugin gives the option to search for product variations and display them inside search results. If you don't need such a feature then it is possible to remove product variations data from the index table.

add_filter( 'aws_indexed_data', 'my_aws_indexed_data', 10, 2 );
function my_aws_indexed_data( $data, $product_id ) {
    if ( $data['type'] === 'child' ) {
        return false;
    }
    return $data;
}

 

aws_create_index_table_sql

apply_filters( 'aws_create_index_table_sql', (string) $sql );

Index table hook. Filters SQL query that will be used to create index table.

Changelog

  • Added in version 2.31

Parameters

  • $sql (string) SQL query string.

Example

Lets modify SQL query and change term column type from VARCHAR(50) to TEXT. New column type can store a larger number of characters for product terms.
When a code snippet is added it is needed to re-index the plugin table in order to affect the changes.

add_filter( 'aws_create_index_table_sql', 'aws_create_index_table_sql' );
function aws_create_index_table_sql( $sql ) {
    $sql = str_replace( 'term VARCHAR(50) NOT NULL DEFAULT 0', 'term TEXT NOT NULL', $sql );
    return $sql;
}

 

aws_extracted_string

apply_filters( 'aws_extracted_string', (string) $string, (string) $source );

Index table hook. Filters extracted from the product data strings before index.

Changelog

  • Added in version 1.33
  • $source parameter - added in version 1.88

Parameters

  • $string (string) String from product data.
  • $source (string) String source.

Example

Lets remove all digits from product title and content sources. This can be useful if you need to ignore digits from the user query and search only for words.

add_filter( 'aws_extracted_string', 'my_aws_extracted_string', 10, 2 );
function my_aws_extracted_string( $string, $source ) {
    if ( $source === 'title' || $source === 'content' ) {
        $string = preg_replace( '/[0-9]+/', '', $string );
    }
    return $string;
}

 

aws_extracted_terms

apply_filters( 'aws_extracted_terms', (array) $str_array, (string) $source );

Index table hook. Filters extracted from the product data strings before index.

Changelog

  • Added in version 1.33
  • $source parameter - added in version 1.88

Parameters

  • $str_array (array) Product terms.
  • $source (string) String source.

Example

For example we enable search by product SKUs. And we notice that often users type inside the search field 0o instead 00. So it is some sort of typo. It is possible to show correct search results even with such mistakes by adding inside the plugin index table both variations of terms: with 00 and with 0o.

add_filter( 'aws_extracted_terms', 'my_aws_extracted_terms', 10, 2 );
function my_aws_extracted_terms( $str_array, $source ) {
    $new_terms = array();
    if ( $str_array && is_array( $str_array ) && ! empty( $str_array ) ) {
        foreach ( $str_array as $str_term => $str_num ) {
            if( strpos( $str_term, '00' ) !== false ) {
                $new_terms[] = str_replace( '00', 'o0', $str_term );
            }
        }
    }
    if ( $new_terms ) {
        foreach( $new_terms as $new_term ) {
            $str_array[$new_term] = 1;
        }
    }
    return $str_array;
}

 
For example we have a product with the term 5555g55. And we want to show it for both search queries 5555g55 or 555555. So we need to separate words and digits for all product terms.

add_filter( 'aws_extracted_terms', 'my_aws_extracted_terms', 10, 2 );
function my_aws_extracted_terms( $str_array, $source ) {
    $new_terms = array();
    if ( $str_array && is_array( $str_array ) && ! empty( $str_array ) ) {
        foreach ( $str_array as $str_term => $str_num ) {
            if ( preg_match( "/b[d]+([^dW]+)[d]+b/i", $str_term, $matches )  ) {
                $new_terms[] = str_replace( $matches[1], '', $str_term );
            }
        }
    }
    if ( $new_terms ) {
        foreach( $new_terms as $new_term ) {
            $str_array[$new_term] = 1;
        }
    }
    return $str_array;
}

 

aws_page_results

apply_filters( 'aws_page_results', (int) $number);

Total number of search results for search results page.

Changelog

  • Added in version 1.00

Parameters

  • $number (int) Total number of product. Default = 100.

Example

Set the total number of items for the search results page to 999.

add_filter( 'aws_page_results', 'my_aws_page_results' );
function my_aws_page_results( $num ) {
    return 999;
}

 

aws_posts_per_page

apply_filters( 'aws_posts_per_page', (int) $number);

Number of search results per page for search results page.

Changelog

  • Added in version 1.00

Parameters

  • $number (int) Number of product per page. Default value depends on current WordPress theme.

Example

Set the number of search results items per page to 12.

add_filter( 'aws_posts_per_page', 'my_aws_posts_per_page' );
function my_aws_posts_per_page( $num ) {
    return 12;
}

 

aws_searchpage_enabled

apply_filters( 'aws_searchpage_enabled', (bool) $is_enabled, (object) $query );

Display or not plugin results for current search results page.

Changelog

  • Added in version 1.00

Parameters

  • $is_enabled (bool) Enable or not plugin search results.
  • $query (object) Query object for current search page.

Example

Current filter gives option to disable plugin search results when needed. For example, let's disable plugin results when we have aws_off GET parameter for current search results page.

add_filter( 'aws_searchpage_enabled', 'my_aws_searchpage_enabled', 10, 2 );
function my_aws_searchpage_enabled( $is_enabled, $query ) {
    if ( isset( $_GET['aws_off'] ) && $_GET['aws_off'] === 'true' ) {
        return false;
    }
    return $is_enabled;
}

 

aws_search_page_results

apply_filters( 'aws_search_page_results', (array) $results, (object) $query, (array) $data );

Array of results for search results page.

Changelog

  • Added in version 1.92

Parameters

  • $results (array) Search results.
  • $query (object) Query object for current search page.
  • $data (array) Search results data array.

Example

It is possible to add a custom product inside the current search results page. Lets add Xeno Superstar Shoes as the first search result.

add_filter( 'aws_search_page_results', 'my_aws_search_page_results', 10, 3 );
function my_aws_search_page_results( $results, $query, $data  ) {

    $post = new stdClass();
    $post->ID = '12283 ';
    $post->site_id = get_current_blog_id();
    $post->post_name = 'Xeno Superstar Shoes';
    $post->post_title = 'Xeno Superstar Shoes';
    $post->permalink = '#';
    $post->post_type = "product";
    $post->post_author = "1";
    $post->post_status = "publish";
    $post->post_parent = 0;
    $post->post_content = "";
    $post->menu_order = 0;
    $post->post_date = "2000-01-01 12:00:00";
    $post->post_date_gmt = "2000-01-01 12:00:00";
    $post->post_modified = "2000-01-01 12:00:00";
    $post->post_modified_gmt = "2000-01-01 12:00:00";
    $post->awssearch = true;

    $results = array( $post ) + $results;

    return $results;

}

 

aws_search_page_query

apply_filters( 'aws_search_page_query', (string) $search_query, (object) $query );

Filter search query string for search results page.

Changelog

  • Added in version 2.22

Parameters

  • $search_query (string) Search query string.
  • $query (object) Query object for current search page.

Example

Lets add additional search word woo for all search queries for the search results page. This means that additionally to user search query results will be shown all products that have word woo inside its content.

add_filter( 'aws_search_page_query', 'my_aws_search_page_query', 10, 2 );
function my_aws_search_page_query( $search_query, $query ) {
    return $search_query . ' woo';
}

 

aws_search_results_products_ids

apply_filters( 'aws_search_results_products_ids', (array) $posts_ids, (string) $s );

Filter the array of product IDs that will be displayed as search results.

Changelog

  • Added in version 1.42

Parameters

  • $posts_ids (array) Product IDs.
  • $s (string) Search query.

Example

We want to show some products at the beginning of the search results list. And what exactly products to show depends on search terms. For example, if a search query contains search term term1 then products with ID 12 and 13 must be displayed first. And for term term2 it must be products 14 and 15.

add_filter( 'aws_search_results_products_ids', 'my_aws_search_results_products_ids', 10, 2 );
function my_aws_search_results_products_ids( $posts_ids, $s ) {
    $terms = array(
        'term1' => array( 12, 13 ),
        'term2' => array( 14, 15 )
    );
    foreach( $terms as $term => $ids ) {
        if ( strpos( $s, $term ) !== false ) {
            foreach( $ids as $id ) {
                if ( $key = array_search( $id, $posts_ids ) ) {
                    unset( $posts_ids[$key] );
                }
            }
            foreach( $ids as $id ) {
                array_unshift( $posts_ids, $id );
            }
        }
    }
    return $posts_ids;
}

 
It is possible to fully hide all products from the search results list. Useful if, for example, you want to display only product categories or tags as search results.

add_filter( 'aws_search_results_products_ids', 'my_aws_search_results_products_ids', 10, 2 );
function my_aws_search_results_products_ids( $posts_ids, $s ) {
    return array();
}

 

aws_search_results_products

apply_filters( 'aws_search_results_products', (array) $products, (string) $s );

Filter the array of products search results.

Changelog

  • Added in version 1.31

Parameters

  • $products (array) Array of products.
  • $s (string) Search query.

Example

Lets order products inside search results by stock status: first display in stock products and out of stock products in the end.

add_filter( 'aws_search_results_products', 'aws_search_results_products', 10, 2 );
function aws_search_results_products( $products, $s ) {
    usort($products, function ($item1, $item2) {
        $product1 = wc_get_product( $item1['id'] );
        $product2 = wc_get_product( $item2['id'] );
        if ( 'outofstock' !== $product1->get_stock_status() ) {
            return -1;
        }
        if ( 'outofstock' !== $product2->get_stock_status() ) {
            return 1;
        }
        return 0;
    });
    return $products;
}

 
Hide products with zero price from the list of search results.

add_filter( 'aws_search_results_products', 'my_aws_search_results_products', 10, 2 );
function my_aws_search_results_products( $products, $s ) {
    $new_array = array();
    foreach ( $products as $product  ) {
        if ( ! isset( $product['f_price'] ) || intval( $product['f_price'] ) !== 0 ) {
            $new_array[] = $product;
        }
    }
    return $new_array;
}

 

aws_search_results_tax_archives

apply_filters( 'aws_search_results_tax_archives', (array) $taxonomies, (string) $s );

Array of enabled for search taxonomies archive pages.

Changelog

  • Added in version 1.54

Parameters

  • $taxonomies (array) Taxonomies slugs.
  • $s (string) Search query.

Example

For example we want to disable search for product categories archive pages if the search form is placed inside product_cat taxonomy archive page.

add_filter( 'aws_search_results_tax_archives', 'my_aws_search_results_tax_archives', 10, 2 );
function my_aws_search_results_tax_archives( $taxonomies, $s ) {
    if ( is_tax( 'product_cat' ) ) {
        foreach( $taxonomies as $tax_key => $tax_slug ) {
            if ( $tax_slug === 'product_cat' ) {
                unset( $taxonomies[$tax_key] );
            }
        }
    }
    return $taxonomies;
}

 

aws_search_results_all

apply_filters( 'aws_search_results_all', (array) $results, (string) $s );

Filter all search results before displaying them inside the search results list.

Changelog

  • Added in version 1.32

Parameters

  • $results (array) Array of search results.
  • $s (string) Search query.

Example

We have users with role dc_vendor and want to display them inside the search results block at the first position.

add_filter( 'aws_search_results_all', 'my_aws_search_results_all', 10, 2 );
function my_aws_search_results_all( $results, $s ) {
    $vendors = get_users( array(
        'role'    => 'dc_vendor',
        'orderby' => 'user_nicename',
        'order'   => 'ASC'
    ) );
    if ( $vendors ) {
        foreach( $vendors as $vendor ) {
            $name = $vendor->data->user_nicename;
            $new_result = array(
                'name'     => $name,
                'link'     => '/store/' . $name,
            );
            $results['tax']['user'][] = $new_result;
        }
    }
    return $results;
}

 

aws_search_terms

apply_filters( 'aws_search_terms', (array) $terms );

Filters array of search terms before generating SQL query.

Changelog

  • Added in version 1.38

Parameters

  • $terms (array) Array of search terms.

Example

For example we have a product with the term 5555g55. And we want to show it for both search queries 5555g55 or 555555. So we need to separate words and digits for all product terms.

add_filter( 'aws_search_terms', 'my_aws_search_terms' );
function my_aws_search_terms( $terms ) {
    $new_terms = array();
    if ( $terms ) {
        foreach( $terms as $term ) {
            if ( preg_match( "/[d]+/i", $term ) ) {
                if ( preg_match( "/b([^dW]+)([d]+)b/i", $term, $matches ) || preg_match( "/b([d]+)([^dW]+)b/i", $term, $matches ) ) {
                    if ( strlen( $matches[1] ) > 1 ) {
                        $new_terms[] = $matches[1];
                    }
                    if ( strlen( $matches[2] ) > 1 ) {
                        $new_terms[] = $matches[2];
                    }
                }
            }
        }
        if ( ! empty( $new_terms ) ) {
            $terms = array_merge( $terms, $new_terms );
        }
    }
    return $terms;
}

 

aws_tax_filter_include_childs

apply_filters( 'aws_tax_filter_include_childs', (bool) $include, (int) $form_id, (int) $filter_id );

When using exclude/include filters it is possible to filter search results by specific taxonomy terms. By default filter will apply and to all child terms too. But this behavior can be changed.

Changelog

  • Added in version 1.75

Parameters

  • $include (bool) Include or not child terms.
  • $form_id (int) Search form ID. Only for PRO plugin version.
  • $filter_id (int) Search form filter ID. Only for PRO plugin version.

Example

Disable applying filters for the child terms.

add_filter( 'aws_tax_filter_include_childs', 'my_aws_tax_filter_include_childs' );
function my_aws_tax_filter_include_childs( $include, $form_id, $filter_id ) {
    return false;
}

 

aws_exclude_products

apply_filters( 'aws_exclude_products', (array) $products, (int) $form_id, (int) $filter_id );

Filter the array of product IDs that must be excluded from the search results.

Changelog

  • Added in version 1.70

Parameters

  • $products (array) Array of product IDs.
  • $form_id (int) Search form ID. Only for PRO plugin version.
  • $filter_id (int) Search form filter ID. Only for PRO plugin version.

Example

Lets hide products with IDs 75, 78 and 83 from the search results for non logged-in users.

add_filter( 'aws_exclude_products', 'my_aws_exclude_products', 10, 3 );
function my_aws_exclude_products( $products, $form_id, $filter_id ) {
    if ( ! is_user_logged_in() ) {
        $products[] = 75;
        $products[] = 78;
        $products[] = 83;
    }
    return $products;
}

 

aws_search_current_lang

apply_filters( 'aws_search_current_lang', (string) $lang, (int) $form_id, (int) $filter_id );

On what language to display search results. Contains active language code of the current page.

Changelog

  • Added in version 1.50

Parameters

  • $lang (string) Language code.
  • $form_id (int) Search form ID. Only for PRO plugin version.
  • $filter_id (int) Search form filter ID. Only for PRO plugin version.

Example

By default the plugin will show search results on the language of the current page. Lets change this and just show all available products translations.

add_filter( 'aws_search_current_lang', 'my_aws_search_current_lang', 10, 3 );
function my_aws_search_current_lang( $lang, $form_id, $filter_id ) {
    return '';
}

 

aws_search_query_array

apply_filters( 'aws_search_query_array', (array) $query, (int) $form_id, (int) $filter_id );

Filter search query parameters.

Changelog

  • Added in version 1.59

Parameters

  • $query (array) Search query parameters.
  • $form_id (int) Search form ID. Only for PRO plugin version.
  • $filter_id (int) Search form filter ID. Only for PRO plugin version.

Example

Add more relevance score form terms that were found inside product tags.

add_filter( 'aws_search_query_array', 'my_aws_search_query_array' );
function my_aws_search_query_array( $query ) {
    $relevance = "( case when ( term_source = 'tag' ) then 250 else 0 end ) +";
    $query['relevance'] = preg_replace( '/(SUM([sS]*?([sS]*?case[sS]*?end[sS]*?)[sS]*?+/i', '$0' . $relevance, $query['relevance'] );
    return $query;
}

 
Don't show products with a publish date earlier than 2014-01-01. In this example we also need to use aws_search_query_string filter.

add_filter( 'aws_search_query_array', 'my_aws_search_query_array' );
function my_aws_search_query_array( $query ) {
    global $wpdb;

    $date = '2014-01-01 00:00:00';

    $table = $wpdb->prefix . AWS_INDEX_TABLE_NAME;

    $query['select'] = str_replace( 'ID', $table . '.ID', $query['select'] );
    $query['search'] .= "AND {$table}.ID = {$wpdb->posts}.ID AND {$wpdb->posts}.post_date > STR_TO_DATE('{$date}', '%Y-%m-%d %H:%i:%s')";

    return $query;
}

add_filter( 'aws_search_query_string', 'my_aws_search_query_string' );
function my_aws_search_query_string( $sql ) {
    global $wpdb;
    $sql = str_replace( 'FROM', 'FROM ' . $wpdb->posts . ',', $sql );
    return $sql;
}

 

aws_search_query_string

apply_filters( 'aws_search_query_string', (string) $sql, (int) $form_id, (int) $filter_id );

Filter search query SQL string.

Changelog

  • Added in version 2.06

Parameters

  • $sql (string) SQL string.
  • $form_id (int) Search form ID. Only for PRO plugin version.
  • $filter_id (int) Search form filter ID. Only for PRO plugin version.

Example

Limit search results to only 5 products.

add_filter( 'aws_search_query_string', 'my_aws_search_query_string' );
function my_aws_search_query_string( $sql ) {
    $sql = str_replace( 'LIMIT 0, 10', 'LIMIT 0, 5', $sql );
    return $sql;
}

 

aws_title_search_result

apply_filters( 'aws_title_search_result', (string) $title, (int) $product_id, (object) $product);

Product title inside search results list.

Changelog

  • Added in version 1.00

Parameters

  • $title (string) Product title.
  • $product_id (int) Product id.
  • $product (object) Product object.

Example

For example we have a product custom field YOUR_FIELD and want to display its value inside the product title for search results.

add_filter( 'aws_title_search_result', 'my_aws_title_search_result', 10, 3 );
function my_aws_title_search_result( $title, $product_id, $product ) {
    $field = get_post_meta( $product_id, 'YOUR_FIELD', true );
    if ( $field ) {
        $title = $title . '<br>' . $field;
    }
    return $title;
}

 

aws_excerpt_search_result

apply_filters( 'aws_excerpt_search_result', (string) $excerpt, (int) $product_id, (object) $product);

Filter product description inside search results list.

Changelog

  • Added in version 1.00

Parameters

  • $excerpt (string) Product description.
  • $product_id (int) Product id.
  • $product (object) Product object.

Example

We have Advanced Custom Fields ( ACF ) plugin installed and with its help created acf_test_field product field. It is possible to display the value from these fields inside the product description when displaying plugin search results.

add_filter( 'aws_excerpt_search_result', 'my_aws_excerpt_search_result', 10, 3 );
function my_aws_excerpt_search_result( $excerpt, $product_id, $product ) {
    $field_name = 'acf_test_field';
    if ( function_exists( 'get_field' ) ) {
        $field = get_field( $field_name, $product_id );
        if ( $field ) {
            $excerpt .= '<br>' . $field;
        }
    }
    return $excerpt;
}

 

aws_search_pre_filter_products

apply_filters( 'aws_search_pre_filter_products', (array) $products, (array) $data);

Filter products array before the output.

Changelog

  • Added in version 1.51

Parameters

  • $products (array) Products array.
  • $data (array) Additional product data.

Example

Hide products price for non logged-in users.

add_filter( 'aws_search_pre_filter_products', 'my_aws_search_pre_filter_products' );
function my_aws_search_pre_filter_products( $products ) {
    if ( $products && ! empty( $products ) ) {
        foreach ( $products as $key => $product ) {
            if ( $product['price'] && ! is_user_logged_in() ) {
                $products[$key]['price'] = '';
            }
        }
    }
    return $products;
}

 
Change Add to cart button success text and View cart link.

add_filter( 'aws_search_pre_filter_products', 'my_aws_search_pre_filter_products' );
function my_aws_search_pre_filter_products( $products ) {
    if ( $products && ! empty( $products ) ) {
        foreach ( $products as $key => $product ) {
            if ( $product['add_to_cart'] ) {
                $products[$key]['add_to_cart']['i18n_view_cart'] = esc_attr__( 'Added', 'advanced-woo-search' );
                $products[$key]['add_to_cart']['cart_url'] = '';
            }
        }
    }
    return $products;
}

 

aws_image_size

apply_filters( 'aws_image_size', (string) $image_size );

Size of product images inside search results block.

Changelog

  • Added in version 2.06

Parameters

  • $image_size (string) Image size. Default = 'thumbnail'.

Example

Change products image size to full.

add_filter( 'aws_image_size', 'my_aws_image_size' );
function my_aws_image_size( $image_size ) {
    return 'full';
}

 

aws_highlight_tag

apply_filters( 'aws_highlight_tag', (string) $tag );

Tag to use for highlighting search words inside the content.

Changelog

  • Added in version 1.79

Parameters

  • $tag (string) HTML tag to use for wrapping searched words. Default strong.

Example

Change HTML highlighting tag to i.

add_filter( 'aws_highlight_tag', 'my_aws_highlight_tag' );
function my_aws_highlight_tag( $tag ) {
    return 'i';
}

 

aws_tax_search_data

apply_filters( 'aws_tax_search_data', (array) $data, (array) $taxonomy );

Filters the array of taxonomies search data.

Changelog

  • Added in version 1.84

Parameters

  • $data (array) Array of search data.
  • $taxonomy (array) Array of taxonomies slugs to search for.

Example

Lets change search logic for taxonomies archive pages to AND.

add_filter( 'aws_tax_search_data', 'my_aws_tax_search_data', 10, 2 );
function my_aws_tax_search_data( $data, $taxonomy ) {
    $data['search_logic'] = 'and';
    return $data;
}

 

aws_search_terms_number

apply_filters( 'aws_search_terms_number', (int) $num );

Maximal number of taxonomies archive pages inside search results.

Changelog

  • Added in version 1.64

Parameters

  • $num (int) Number of archive pages results. Default = 10.

Example

Changing the maximal number of taxonomies archive pages results to 5.

add_filter( 'aws_search_terms_number', 'my_aws_search_terms_number' );
function my_aws_search_terms_number( $num ) {
    return 5;
}

 

aws_terms_search_query

apply_filters( 'aws_terms_search_query', (string) $sql, (string) $taxonomy, (string) $search_query );

Filter taxonomies archive pages SQL query string.

Changelog

  • Added in version 1.82

Parameters

  • $sql (string) SQL query string.
  • $taxonomy (string) Taxonomy slug to search for.
  • $search_query (string) Search query.

Example

By default the plugin will not show inside search results block taxonomy archive pages that have no products inside. But this can be changed with the following code snippet.

add_filter( 'aws_terms_search_query', 'my_aws_terms_search_query', 10, 3 );
function my_aws_terms_search_query( $sql, $taxonomy, $search_query ) {
    $sql = str_replace( 'AND count > 0', '', $sql );
    return $sql;
}

 

aws_search_tax_results

apply_filters( 'aws_search_tax_results', (array) $result_array, (string) $taxonomy, (string) $search_query );

Filter taxonomies archive pages results.

Changelog

  • Added in version 1.55

Parameters

  • $result_array (array) Taxonomies archive pages.
  • $taxonomy (string) Taxonomy slug to search for.
  • $search_query (string) Search query.

Example

For example we have taxonomy pwb-brand and each of this taxonomy term has a unique image that is stored inside the pwb_brand_image meta field. We want to show this image for each taxonomy term inside the search results block.

add_filter( 'aws_search_tax_results', 'my_aws_search_tax_results', 10, 3 );
function my_aws_search_tax_results( $result_array, $taxonomy, $search_query ) {
    if ( isset( $result_array['pwb-brand'] ) && ! empty( $result_array['pwb-brand'] ) ) {
        foreach ( $result_array['pwb-brand'] as $key => $brand ) {
            $thumb_id = get_term_meta( $brand['id'], 'pwb_brand_image', 1 );
            $thumb_src = wp_get_attachment_image_src( $thumb_id, 'thumbnail' );
            if ( $thumb_src ) {
                $result_array['pwb-brand'][$key]['image'] = $thumb_src[0];
            }
        }
    }
    return $result_array;
}

 

aws_search_terms_description

apply_filters( 'aws_search_terms_description', (bool) $enable );

Search or not inside the taxonomy terms description. By default plugin search only inside terms names.

Changelog

  • Added in version 1.55

Parameters

  • $enable (bool) Enable or not searching inside terms description. Default false.

Example

Enable searching inside taxonomies terms description.

add_filter( 'aws_search_terms_description', 'my_aws_search_terms_description' );
function my_aws_search_terms_description( $enable ) {
    return true;
}

 

aws_search_tax_exclude

apply_filters( 'aws_search_tax_exclude', (array) $exclude, (array) $taxonomy, (string) $search_query );

Exclude certain taxonomies terms archive pages from the search results.

Changelog

  • Added in version 1.83

Parameters

  • $exclude (array) IDs array of taxonomies archive pages terms to exclude.
  • $taxonomy (array) Taxonomies slugs.
  • $search_query (string) Search query.

Example

Exclude taxonomy term with ID 19 from the search.

add_filter( 'aws_search_tax_exclude', 'my_aws_search_tax_exclude', 10, 3 );
function my_aws_search_tax_exclude( $exclude, $taxonomy, $search_query ) {
    $exclude[] = 19;
    return $exclude;
}

 

'aws_terms_exclude_' . $taxonomy

apply_filters( 'aws_terms_exclude_' . $taxonomy, (array) $exclude );

Exclude certain terms archive pages from the search results.

Changelog

  • Added in version 1.49

Parameters

  • $exclude (array) Array of taxonomy tems IDs that need to exclude.

Example

Exclude from the search term with ID 125 that belongs to product_cat taxonomy.

add_filter( 'aws_terms_exclude_product_cat', 'my_aws_terms_exclude_product_cat' );
function my_aws_terms_exclude_product_cat( $exclude ) {
    $exclude[] = 125;
    return $exclude;
}

 

aws_users_search_data

apply_filters( 'aws_users_search_data', (array) $data, (array) $roles );

Filters the array of users search data.

Changelog

  • Added in version 2.04

Parameters

  • $data (array) Array of search data.
  • $roles (array) Array of user roles to search for.

Example

Lets change search logic for user archive pages to AND.

add_filter( 'aws_users_search_data', 'my_aws_users_search_data', 10, 2 );
function my_aws_users_search_data( $data, $roles ) {
    $data['search_logic'] = 'and';
    return $data;
}

 

aws_users_search_args

apply_filters( 'aws_users_search_args', (array) $args );

Filter users search query arguments that will pass to get_users WordPress function.

Changelog

  • Added in version 2.04

Parameters

  • $args (array) Arguments for get_users function.

Example

Customize users search results order. By default users ordered by login. Let's change it and order users results by post_count.

add_filter( 'aws_users_search_args', 'my_aws_users_search_args' );
function my_aws_users_search_args( $args ) {
    $args['orderby'] = 'post_count';
    return $args;
}

 

aws_users_search_query

apply_filters( 'aws_users_search_query', (string) $sql, (string) $roles, (string) $search_query );

Filter users archive pages SQL query string.

Changelog

  • Added in version 2.04

Parameters

  • $sql (string) SQL query string.
  • $roles (string) User roles to search for.
  • $search_query (string) Search query.

Example

By default users inside search results block order by ID. We can change this behavior and order users by, for example, display_name.

add_filter( 'aws_users_search_query', 'my_aws_users_search_query', 10, 3 );
function my_aws_users_search_query( $sql, $roles, $search_query ) {
    $sql = str_replace( 'GROUP BY ID', 'GROUP BY display_name', $sql );
    return $sql;
}

 

aws_search_users_results

apply_filters( 'aws_search_users_results', (array) $results, (string) $roles, (string) $search_query );

Filter user archive pages results.

Changelog

  • Added in version 2.04

Parameters

  • $results (array) Users archive pages.
  • $roles (string) User roles to search for.
  • $search_query (string) Search query.

Example

Customize users archive page URL inside search results block. Change it to '/?user-id=' . $user_id.

add_filter( 'aws_search_users_results', 'my_aws_search_users_results', 10, 3 );
function my_aws_search_users_results( $results, $roles, $search_query ) {
    if ( $results ) {
        foreach( $results as $user_id => $user ) {
            $results[$user_id][0]['link'] = '/?user-id=' . $user_id;
        }
    }
    return $results;
}

 

aws_js_seamless_selectors

apply_filters( 'aws_js_seamless_selectors', (array) $selectors );

Filter css selectors for js seamless integration. Sometimes it is not possible to replace standard search form with the plugin ones with help of any php hooks. In this case there is an option to do replacement with the help on js code. It is only needed to specify css selector of forms that need to be replaced.

Changelog

  • Added in version 1.76

Parameters

  • $selectors (array) Array of css selectors.

Example

We are using the Woodmart theme and want to replace its search form with the plugin ones. In this case we specify selectors .woodmart-search-form form, form.woodmart-ajax-search for search forms that will be replaced.

add_filter( 'aws_js_seamless_selectors', 'my_aws_js_seamless_selectors' );
function my_aws_js_seamless_selectors( $selectors ) {
    $theme = wp_get_theme();
    if ( 'Woodmart' === $theme->name ) {
        $selectors[] = '.woodmart-search-form form, form.woodmart-ajax-search';
    }
    return $selectors;
}

 

aws_js_seamless_form_id

apply_filters( 'aws_js_seamless_form_id', (int) $form_id );

Form that will be used for JS seamless integration.

Changelog

  • Added in version 1.82

Parameters

  • $form_id (int) Search form ID. Default - 1

Example

Set search form with ID 2 as default form for JS seamless integration.

add_filter( 'aws_js_seamless_form_id', 'my_aws_js_seamless_form_id' );
function my_aws_js_seamless_form_id( $form_id ) {
    return 2;
}

 

aws_js_seamless_searchbox_markup

apply_filters( 'aws_js_seamless_searchbox_markup', (string) $form_html, (array) $forms );

Filter form markup that used for seamless integration js event.

Changelog

  • Added in version 2.25

Parameters

  • $form_html (string) Form html output
  • $forms (array) Array of css selectors for forms replays

Example

We are using some theme where it is possible to replace default search forms with the plugin ones only via js seamless integration hook. And we want to inherit current theme search form styles and also its default search form. To do this we need to change AWS plugin search form markup. We find that theme styles can be inherited if add search-form class name for plugin search form. Also we need to add some html markup for the search button.

add_filter( 'aws_js_seamless_searchbox_markup', 'my_aws_js_seamless_searchbox_markup' );
function my_aws_js_seamless_searchbox_markup( $markup ) {
    $button = '<a href="#" class="search-btn">' . lab_get_svg( "images/search.svg" ) . '<span class="sr-only">' . __( "Search", "aurum" ) .'</span></a>';
    $markup = str_replace( '</form>', $button . '</form>', $markup );
    $markup = str_replace( 'aws-search-form', 'aws-search-form search-form', $markup );
    return $markup;
}

 

aws_search_start

do_action( 'aws_search_start', (string) $s, (int) $form_id, (int) $filter_id );

Fires each time when performing the search.

Changelog

  • Added in version 1.50
  • $filter_id parameter - Added in version 2.11

Parameters

  • $s (string) Search string.
  • $form_id (int) Search form ID. Only for PRO plugin version.
  • $filter_id (int) Search form filter ID. Only for PRO plugin version.

Example

add_action( 'aws_search_start', 'my_aws_search_start', 10, 3 );
function my_aws_search_start( $s, $form_id, $filter_id ) {
    // Do any stuff here
}

 

aws_cache_clear

do_action( 'aws_cache_clear' );

Fires each time when the plugin cache was cleared.

Changelog

  • Added in version 1.50

Example

add_action( 'aws_cache_clear', 'my_aws_cache_clear' );
function my_aws_cache_clear() {
    // Do any stuff here
}

 

aws_form_changed

do_action( 'aws_form_changed', (array) $settings, (string) $action_type, (int) $instance_id );

Fires after the search form instance was created/copied/deleted.

Changelog

  • Added in version 1.33

Parameters

  • $settings (array) Search form settings.
  • $action_type (string) Search form action type. Available - copy_form, delete_form, add_form
  • $instance_id (int) Search form ID.

Example

add_action( 'aws_form_changed', 'my_aws_form_changed', 10, 3 );
function my_aws_form_changed( $settings, $action_type, $instance_id ) {
    // Do any stuff here
}

 

aws_filters_changed

do_action( 'aws_filters_changed', (array) $settings, (string) $action_type, (int) $instance_id, (int) $filter_id );

Fires after the search form filter was created/copied/deleted.

Changelog

  • Added in version 1.33

Parameters

  • $settings (array) Search form settings.
  • $action_type (string) Search form action type. Available - add_filter, copy_filter, delete_filter
  • $instance_id (int) Search form ID.
  • $filter_id (int) Search form filter ID.

Example

add_action( 'aws_filters_changed', 'my_aws_filters_changed', 10, 4 );
function my_aws_filters_changed( $settings, $action_type, $instance_id, $filter_id ) {
    // Do any stuff here
}

 

aws_settings_saved

do_action( 'aws_settings_saved', (array) $settings );

Fires after the plugin settings were saved.

Changelog

  • Added in version 1.33

Parameters

  • $settings (array) Plugin settings.

Example

add_action( 'aws_settings_saved', 'my_aws_settings_saved' );
function my_aws_settings_saved( $settings ) {
    // Do any stuff here
}

 

aws_create_index_table

do_action( 'aws_create_index_table' );

Fires when the plugin index table is created.

Changelog

  • Added in version 2.13

Parameters

    Example

    add_action( 'aws_create_index_table', 'my_aws_create_index_table' );
    function my_aws_create_index_table() {
        // Do any stuff here
    }
    

     

    aws_index_complete

    do_action( 'aws_index_complete', (array) $index_meta );

    Fires once the index process is complete.

    Changelog

    • Added in version 2.13

    Parameters

    • $index_meta (array) Index meta data. Contains such data like total indexed posts and products offset.

    Example

    add_action( 'aws_index_complete', 'my_aws_index_complete' );
    function my_aws_products_order_by( $index_meta ) {
        // Do any stuff here
    }