1. Documentation /
  2. WooCommerce Product Search /
  3. API /
  4. Filters

Filters

product_search_limit

↑ Back to top
This filter allows to alter the limit on the number of results produced for the Product Search Field. Arguments:
  • $limit intthe number of results
Return: int the number of results

single_term_title

↑ Back to top
Allows to modify the category name displayed for categories shown on the Product Search Field. Arguments:
  • $name stringthe category name
Return: string the category name

widget_title

↑ Back to top
Allows to modify the widget title displayed on the various widgets. Arguments:
  • $title stringthe title
Return: string the title

woocommerce_product_filter_placeholder

↑ Back to top
Modifies the placeholder shown on the Product Filter Field. Arguments:
  • $placeholder string the placeholder
Return: string the placeholder to use

woocommerce_product_search_avoid_redirect_canonical_loops

↑ Back to top
This filter determines whether the search engine will try to avoid redirect loops caused by URL transformations outside the scope of its influence. At WordPress 5.7.2 and WordPress 5.8 alpha, filter requests URLs can wrongly be transformed from uppercase URL-encoded characters to lowercase URL-encoded characters and redirected, causing infinite redirect loops. Arguments:
  • $avoid boolean whether to avoid redirect loops
Return: boolean whether to apply the search engine’s solution to avoid redirect loops

woocommerce_product_search_process_query_object_term_limit

↑ Back to top
Limits the number of different terms that can be requested via filters. Arguments:
  • $limit int maximum number of terms per filter request, defaults to 100
Return: int number of terms

woocommerce_product_search_process_query_product_taxonomies

↑ Back to top
This filter is used to determine whether a product taxonomy will be processed during the search engine’s query processing routine. Arguments:
  • $product_taxonomies string[] product taxonomies
  • $wp_query WP_Query the query instance
Return: string[] product taxonomies to process

woocommerce_product_search_auto_toggle_filter_widgets

↑ Back to top
This filter determines whether filter widgets should be toggled automatically. Arguments:
  • $toggle boolean whether to toggle filter widgets automatically, default: true
Return: boolean whether to toggle filter widgets

woocommerce_product_search_cache_lifetime

↑ Back to top
This filter allows to modify the cache lifetime for stored results, the value is in seconds. Arguments:
  • $lifetime intthe number of seconds
Return: int the number of seconds

woocommerce_product_search_compat

↑ Back to top
This filter allows to choose whether a compatibility resource will be loaded or not. Arguments:
  • $load boolean whether to load the compatibility resource
  • $what string either “plugin” or “theme” indicating whether the compatibility resources for a plugin or for a theme should be loaded
  • $name string the name of the plugin or theme for which the compatibility resources should be loaded
Return: boolean this filter must return true if compatibility resources should be loaded for the given plugin or theme, false otherwise

woocommerce_product_search_compat_woocommerce_brands_index

↑ Back to top
This filter allows to enable/disable indexing of brands related to products, integrating with the WooCommerce Brands extension. Arguments:
  • $enable boolean whether to index brands related to products, enabled by default
Return:
  • boolean true if brands should be indexed, otherwise false

woocommerce_product_search_compat_woocommerce_product_vendors_index

↑ Back to top
This filter allows to enable/disable indexing of vendors related to products, integrating with the WooCommerce Product Vendors extension. Arguments:
  • $enable boolean whether to index vendors related to products, enabled by default
Return:
  • boolean true if vendors should be indexed, otherwise false

woocommerce_product_search_ext_product_data_store

↑ Back to top
Whether to use the extended product data store used to power back end and JSON product searches. Arguments:
  • $load boolean takes the default value from the WPS_EXT_PDS constant
Return: boolean whether to load the data store

woocommerce_product_search_field_product_add_to_cart_html

↑ Back to top
Allows to alter the HTML for the button that allows to add a product to the cart. Applies to the results presented for the live search field. Use with caution as malformed HTML will corrupt the structure of the results displayed. Arguments:
  • $add_to_cart_html stringthe HTML for the button
  • $post_id int the product’s ID
Return: string the HTML for the button

woocommerce_product_search_field_product_description

↑ Back to top
Allows to alter the description of a product. Applies to the results presented for the live search field. Use with caution as malformed HTML will corrupt the structure of the results displayed. Arguments:
  • $description string the description
  • $post_id int the product’s ID
Return: string the description

woocommerce_product_search_field_product_price_html

↑ Back to top
Allows to alter the HTML for the price displayed of a product. Applies to the results presented for the live search field. Use with caution as malformed HTML will corrupt the structure of the results displayed. Arguments:
  • $price_html stringthe HTML for the price
  • $post_id int the product’s ID
Return: string the HTML for the price

woocommerce_product_search_field_product_title

↑ Back to top
Allows to alter the title displayed for a product. Applies to the results presented for the live search field. Use with caution as malformed HTML will corrupt the structure of the results displayed. Arguments:
  • $title string the title
  • $post_id int the product’s ID
Return: string the title

woocommerce_product_search_field_more_anchor_title

↑ Back to top
Allows to alter the text displayed when there are more results in the Product Search Field. The translatable string "Search for more …" is the default. Arguments:
  • $text stringthe title of the more link
Return: string the title of the more link

woocommerce_product_search_field_more_title

↑ Back to top
Allows to alter the text displayed when there are more results in the Product Search Field. The translatable string "more …" is the default. Arguments:
  • $text stringthe text shown in the more link
Return: string the text shown in the more link

woocommerce_product_search_filter_auto_append

↑ Back to top
This determines whether the Product Search Filter is automatically appended when its presence is not detected but filters are used. Arguments:
  • $auto_append boolean whether to append the filter automatically, default: true
Return: boolean whether to append the filter automatically

woocommerce_product_search_filter_heading_allowed_elements

↑ Back to top
Allows to modify the allowed HTML elements in filter headings. Arguments:
  • $tags arraythe allowed HTML elements
Return: array the allowed HTML elements

woocommerce_product_search_filter_price_decimals

↑ Back to top
This filter allows to modify the number of decimals used for the price filter provided by the Product Filter – Price widget, the [woocommerce_product_filter_price] shortcode and the equivalent API function. Arguments:
  • $decimals int number of decimals
Return: int number of decimals

woocommerce_product_search_service_min_max_price_adjust_decimals

↑ Back to top
Allows to modify the number of decimals used to calculate minimum and maximum price limits used by the Product Filter – Price widget, the [woocommerce_product_filter_price] shortcode and the equivalent API function. Arguments:
  • $decimals int number of decimals
Return: int number of decimals

woocommerce_product_search_service_min_max_price_adjust_for_display_decimals

↑ Back to top
Allows to modify the number of decimals used to display the minimum and maximum price limits used by the Product Filter – Price widget, the [woocommerce_product_filter_price] shortcode and the equivalent API function. Arguments:
  • $decimals int number of decimals
Return: int number of decimals

woocommerce_product_search_filter_price_prefix

↑ Back to top
Filters the prefix displayed before the price filter is rendered. Arguments:
  • $prefix stringthe prefix
Return: string the prefix

woocommerce_product_search_filter_price_suffix

↑ Back to top
Filters the suffix displayed after the price filter is rendered. Arguments:
  • $suffix stringthe suffix
Return: string the suffix

woocommerce_product_search_filter_product_loop_content

↑ Back to top
Filters the content of the product loop. Arguments:
  • $html stringthe content
Return: string the content

woocommerce_product_search_filter_product_loop_prefix

↑ Back to top
Filters the prefix displayed before the product loop. Arguments:
  • $html stringthe prefix
Return: string the prefix

woocommerce_product_search_filter_product_loop_suffix

↑ Back to top
Filters the suffix displayed after the product loop. Arguments:
  • $html stringthe suffix
Return: string the suffix

woocommerce_product_search_filter_products_catalog_ordering

↑ Back to top
Filters the HTML that displays the catalog ordering. Arguments:
  • $html stringthe catalog ordering HTML output
Return: string the catalog ordering HTML

woocommerce_product_search_filter_products_pagination

↑ Back to top
Filters the HTML that displays the pagination. Arguments:
  • $html stringthe pagination HTML output
Return: string the pagination HTML

woocommerce_product_search_filter_products_prefix_close

↑ Back to top
Filters the closing of the prefix that is rendered before product results are displayed. Arguments:
  • $html stringthe prefix closing
Return: string the prefix closing

woocommerce_product_search_filter_products_prefix_open

↑ Back to top
Filters the opening of the prefix that is rendered before product results are displayed. Arguments:
  • $html stringthe prefix opening
Return: string the prefix opening

woocommerce_product_search_filter_products_suffix_close

↑ Back to top
Filters the closing of the suffix that is rendered after product results are displayed. Arguments:
  • $html stringthe suffix closing
Return: string the suffix closing

woocommerce_product_search_filter_products_suffix_open

↑ Back to top
Filters the opening of the suffix that is rendered after product results are displayed. Arguments:
  • $html stringthe suffix opening
Return: string the suffix opening

woocommerce_product_search_filter_products_result_count

↑ Back to top
Filters the HTML that displays the results count. Arguments:
  • $html stringthe results count
Return: string the results count

woocommerce_product_search_filter_sale_prefix

↑ Back to top
Filters the prefix displayed before the sale filter is rendered. Arguments:
  • $prefix stringthe prefix
Return: string the prefix

woocommerce_product_search_filter_sale_suffix

↑ Back to top
Filters the suffix displayed after the sale filter is rendered. Arguments:
  • $suffix stringthe suffix
Return: string the suffix

woocommerce_product_search_filter_shortcode_products

↑ Back to top
This filters allows to determine whether the search engine should filter the standard WooCommerce [products] shortcode. The default behavior is determined via the value of the WPS_SHORTCODES_PRODUCTS_FILTER constant. Its value is false unless defined otherwise. Arguments:
  • $filter boolean whether to filter the shortcode
Return: boolean whether to filter the shortcode

woocommerce_product_search_filter_shortcode_products_query

↑ Back to top
Filters the query arguments used to retrieve products. Arguments:
  • $query_args arraythe query parameters
  • $atts array the shortcode attributes
  • $loop_name string identifies the product filter loop
Return: array the query parameters

woocommerce_product_search_filter_stock_stock_counts

↑ Back to top
This filter allows to modify the stock counts used by the search engine’s stock filter to determine whether there are any products in stock, on backorder and out of stock. For the purpose of displaying a stock filter using the Product Filter – Stock widget, the [woocommerce_product_filter_stock] shortcode or the equivalent API function, the search engine considers that products are available when the sum of instock and onbackorder is greater than zero. Arguments:
  • $counts array the stock counts indexed by instock, outofstock and onbackorder
Return: array the stock counts

woocommerce_product_search_filter_stock_stock_counts_cache_expire

↑ Back to top
This filter allows to modify the time period in seconds until cached stock counts expire. Arguments:
  • $expire int seconds until cached stock counts expire
Return: int seconds until cached stock counts expire

woocommerce_product_search_filter_{$taxonomy}_args

↑ Back to top
Allows to modify the arguments used to retrieve terms for the taxonomy. Arguments:
  • $params array the arguments used to retrieve taxonomy terms
Return: array the arguments to use

woocommerce_product_search_filter_{$taxonomy}_content

↑ Back to top
Filters the content displayed for the taxonomy filter. Arguments:
  • $content stringthe content
Return: string the content

woocommerce_product_search_filter_{$taxonomy}_prefix

↑ Back to top
Filters the prefix displayed before the taxonomy filter is rendered. Arguments:
  • $prefix stringthe prefix
Return: string the prefix

woocommerce_product_search_filter_{$taxonomy}_suffix

↑ Back to top
Filters the suffix displayed after the taxonomy filter is rendered. Arguments:
  • $suffix stringthe suffix
Return: string the suffix

woocommerce_product_search_filter_terms

↑ Back to top
This filter determines whether term filters will be applied or not. Arguments:
  • $filter boolean whether to filter terms, default: true
Return: boolean whether to filter terms

woocommerce_product_search_filter_terms_always

↑ Back to top
This filter decides whether terms will be filtered always or only before the shop loop. Arguments:
  • $filter boolean whether to filter terms, default: false
Return: boolean whether to filter terms always

woocommerce_product_search_get_min_max_price

↑ Back to top
This filter allows to modify the minimum and maximum price used to delimit the values that can be used with the Product Filter – Price widget, the shortcode [woocommerce_product_filter_price] and the equivalent woocommerce_product_search_filter_price() API function. Arguments:
  • $min_max array holds limits indexed by keys 'min_price' and 'max_price'
Return: array limits

woocommerce_ product_search_get_terms_args_apply

↑ Back to top
Allows to exit before the get_terms_args filter is processed. Arguments:
  • $apply boolean – whether to apply the search engine’s get_terms_args filter
  • $args array – arguments as supplied to the filter
  • $taxonomies array – taxonomies as supplied to the filter
Return: boolean whether to apply the filter

woocommerce_product_search_get_terms_args_process_terms

↑ Back to top
This filter determines whether to process terms within get_terms_args. Arguments:
  • $process_terms boolean whether to process terms
  • $args array arguments from get_terms_args
  • $taxonomies array involved taxonomies
Return: boolean whether to process terms

woocommerce_product_search_get_terms_args_process_terms_search

↑ Back to top
This filter determines whether to process terms based on the requested search within get_terms_args. Arguments:
  • $process_terms boolean whether to process terms
  • $is_search_request boolean whether this is a search request
  • $args array arguments from get_terms_args
  • $taxonomies array involved taxonomies
Return: boolean whether to process terms

woocommerce_product_search_get_terms_args_process_terms_taxonomies

↑ Back to top
This filter determines whether to process terms based on the requested terms within get_terms_args. Arguments:
  • $process_terms boolean whether to process terms
  • $is_terms_request boolean whether this is a request for terms
  • $args array arguments from get_terms_args
  • $taxonomies array involved taxonomies
Return: boolean whether to process terms

woocommerce_product_search_get_terms_args_stop_args

↑ Back to top
Allows to set or modify the arguments used to abandon the get_terms_args filter before processing. When any of the arguments are found provided in the filter invocation’s arguments, processing will not occur. Arguments:
  • $stop_args array an array of strings identifying the stop args
Return: array the array of stop args

woocommerce_product_search_get_terms_filter_counts

↑ Back to top
Determines whether the term counts are adjusted based on current filter settings. Arguments:
  • $adjust boolean – whether to adjust the term counts
  • $terms array – found terms
  • $taxonomies  array – taxonomies in context
  • $args array – get_terms() arguments
  • $term_query WP_Term_Query – term query object
Return: boolean whether to adjust the term counts

woocommerce_product_search_indexer_check_execution_limit

↑ Back to top
Whether the indexer should try to avoid exceeding execution time limits. Arguments:
  • $check_execution_limit boolean whether to check and avoid exceeding the execution time limits
Return: boolean whether to check and avoid exceeding limits

woocommerce_product_search_indexer_check_memory_limit

↑ Back to top
Whether the indexer should try to avoid exceeding memory limits. Arguments:
  • $check_memory_limit boolean whether to check and avoid exceeding the memory limits
Return: boolean whether to check and avoid exceeding limits

woocommerce_product_search_indexer_filter_content

↑ Back to top
Allows to modify or add additional terms to content that is being indexed for a product. Arguments:
  • $content string the content that will be indexed
  • $context string the context for the content being indexed
  • $post_id int the ID of the product being indexed
Return: string the content that will be indexed We provide an example implementation for this filter which is available as a plugin at https://github.com/itthinx/wps-indexer-filter-test – this example will add metadata based on the test_meta key to the product’s content being indexed. The following example will include product metadata for series, part number and manufacturer. The corresponding meta keys are held in the $fields variable:
add_filter(
    'woocommerce_product_search_indexer_filter_content',
    'example_indexer_filter_content',
    10,
    3
);

function example_indexer_filter_content( $content, $context, $post_id ) {
    if ( $context === 'post_content' ) {
        $fields = array( 'series', 'part_number', 'manufacturer' );
        $product = wc_get_product( $post_id );
        $meta_values = array();
        foreach ( $fields as $meta_key ) {
            $meta_value = $product->get_meta( $meta_key );
            if ( !empty( $meta_value ) && is_string( $meta_value ) ) {
                $meta_values[] = $meta_value;
            }
        }
        if ( count( $meta_values ) > 0 ) {
            $content .= ' ' . implode( ' ', $meta_values );
        }
    }
    return $content;
}
The woocommerce_product_search_indexer_filter_content filter can be used together with desired product metadata to include any desired additional information for products. Once the products are again indexed, the search engine will retrieve results based on the added information. This also works with plugins such as Advanced Custom Fields who rely on WordPress’ metadata related to posts. Please note that you need to re-index so the search engine will find the added data.

woocommerce_product_search_indexer_limit

↑ Back to top
Determines the processing limit per cycle. During each indexing cycle, the indexer will try to process up to $limit entries. Arguments:
  • $limit int the maximum number of entries to process per cycle
Return: int the desired limit per cycle

woocommerce_product_search_indexer_object_term_term_ids

↑ Back to top
This filter determines the term IDs that are related to a particular product. Arguments:
  • $term_ids int[] the IDs of the terms related to the product
  • $product WC_Product the product
Return: int[] the IDs of the terms that are related to the product

woocommerce_product_search_like_within

↑ Back to top
This filters determines whether matches for search terms are sought within indexed tokens or not. By default, the filter will return false, only producing exact matches or partial matches that start with search terms. If it returns true, the processing time can increase substantially and have a negative impact on overall performance, although it will be lighter if appropriate caching is used. Example – The following function can be used to enable searches within tokens. This function can be placed within a child theme’s functions.php or preferably encapsulated as a plugin – we have created this plugin (download) which you can install and activate so you won’t need to implement this yourself:
add_filter( 'woocommerce_product_search_like_within', 'enable_wps_search_like_within', 10, 3 );
function enable_wps_search_like_within( $enable, $object_type_ids, $search_terms ) {
    return true;
}
Arguments:
  • $enable boolean whether to search within indexed tokens, default is false
  • $object_type_ids array the type of objects considered to look for tokens
  • $search_terms array the search terms
Return: boolean whether to search within tokens

woocommerce_product_search_no_results

↑ Back to top
Modifies the text shown for the Product Search Field when there are no results. Arguments:
  • $no_results string the text shown for no results
Return: string the text shown for no results

woocommerce_product_search_placeholder

↑ Back to top
Modifies the placeholder shown on the Product Search Field. Arguments:
  • $placeholder string the placeholder
Return: string the placeholder to use

woocommerce_product_search_record_hit

↑ Back to top
This filter is used to decide whether a search query hit should be recorded. Arguments:
  • $record boolean whether to record the hit, default: true
  • $query string the query string
  • $count int the number of results founds for the query string
  • $filter_args array additional information about the context
Return: boolean whether to record the hit

woocommerce_product_search_request_search_query

↑ Back to top
This filter allows to modify the search query that is received by the search engine in a request. Arguments:
  • $search_query string the search as provided in the request
Return: string the search to be handled by the search engine

woocommerce_product_search_selectize_css

↑ Back to top
Allows to switch the CSS loaded for the dropdown style based on selectize. Determines which selectize stylesheet is loaded and takes one argument, ‘selectize’ by default. Arguments:
  • $selectize_css string the selectize CSS to load, allowed: “selectize” (default), “selectize.default”, “selectize.bootstrap2”, “selectize.bootstrap3” and “selectize.legacy”
Return: string the CSS to use

woocommerce_product_search_shorten_ellipsis

↑ Back to top
With this filter the ellipsis used for shortened content can be modified. This does not alter the content. Arguments:
  • $ellipsis string the ellipsis
  • $content string the content to shorten
  • $what string kind of content, “description” or “title”
Return: string the ellipsis to use

woocommerce_product_search_shutdown_remove_all_actions

↑ Back to top
During filter requests, the search engine will minimize any interference from other extensions when shutdown hooks are executed. While this is enabled by default, this filter can be used to inhibit the search engine from doing so during filter requests (not recommended). Arguments:
  •  $remove boolean whether to remove all shutdown actions
Return: boolean remove all shutdown actions

woocommerce_product_search_term_node_select_apply_padding

↑ Back to top
This applies when a term filter is rendered as a select. Whether to apply padding to a term rendered within a select. Arguments:
  • $apply_padding boolean whether to apply padding
  • $term WP_Term the term to render
  • $depth int the depth in the term hierarchy at which the term is located
Return: boolean whether to apply padding

woocommerce_product_search_term_node_select_padding

↑ Back to top
This applies when a term filter is rendered as a select. Determines the expanded padding string prepended to a term rendered as an option within the select. Arguments:
  • $expanded_padding string the full string that will prefix the term shown
  • $term WP_Term the term to render
  • $depth int the depth in the term hierarchy at which the term is located
Return: string the padding string

woocommerce_product_search_term_node_select_padding_step

↑ Back to top
Determines the step width in pixels used for padding (padding pixels = depth * step) – default is 8 – return value must be numeric and is converted to int. Arguments:
  • $padding_step int the padding step width, default: 8
  • $term WP_Term the term to render
  • $depth int the depth in the term hierarchy at which the term is located
Return: int the padding step

woocommerce_product_search_term_node_select_padding_string

↑ Back to top
This applies when a term filter is rendered as a select. Determines the string used to build the prepended padding when a term is rendered as an option within a select. This string is repeated multiple times depending on the depth at which the term is located within the hierarchy. The default string used can be overridden with this filter. Arguments:
  • $padding string the full string prepended
  • $term WP_Term the term to render
  • $depth int the depth in the term hierarchy at which the term is located
Return: string the padding string

woocommerce_product_search_term_node_select_render_count

↑ Back to top
Allows to modify the output that displays the number of related products for a term. This filter is called when displaying counts on filter terms. Arguments:
  • $object_count_display string the number of related objects (products) for the filter term; defaults to the string ” (n)” where n is the number of related objects
  • $term WP_Term the term to render
  • $depth int the depth in the term hierarchy at which the term is located
  • $object_count int the count (the n in the default string)
Return: string the desired output to display the object count for the term

woocommerce_product_search_term_walker_anchor_content

↑ Back to top
Allows to modify the anchor content for a term rendered in a term filter. Arguments:
  • $anchor_content string current anchor content
  • $object object the data object
  • $depth int the depth of the item
  • $args array context arguments
  • $current_object_id int the ID of the current item
Return: string anchor content

woocommerce_product_search_term_walker_expand

↑ Back to top
This filter allows to modify the string used to render a term’s expander. The default is Font Awesome’s “plus” – the HTML entity reference . Arguments:
  • $expander string the current expander used
  • $object object the data object
Return: string the expander to use

woocommerce_product_search_term_walker_retract

↑ Back to top
This filter allows to modify the string used to render a term’s retractor. The default is Font Awesome’s “minus” – the HTML entity reference . Arguments:
  • $retractor string the current retractor used
  • $object object the data object
Return: string the retractor to use

woocommerce_product_search_filter_divi_shop

↑ Back to top
This filter is used to determine whether instances of the Divi Shop module should be filtered. Arguments:
  • $filter boolean whether instances of the Divi Shop module should be filtered. The default value is determined by the value of the WPS_DIVI_SHOP_FILTER constant which is true by default.
Return: boolean whether to filter