Filters

Collection of helper methods to work with filters.

Table of Contents

array_remove_empty()  : array<string|int, mixed>
Recursively remove empty values for an array.
calculate_max_price()  : mixed
Find the highest price indexed and save it into the database.
custom_field_exists()  : bool
Determines if a given custom field exists.
filter_visible_terms()  : array<string|int, mixed>
Filter the list of terms to only include the ones that are used as variations for the current product.
flatten_results()  : array<string|int, mixed>
Flatten the collection of results and return only the post_id.
generate_child_filters()  : void
Generate child filters for an attribute type of filter.
generate_ranged_taxonomy_index_data()  : array<string|int, mixed>
Helper function that generates an array of taxonomy related data.
generate_taxonomy_index_data()  : array<string|int, mixed>
Helper function that generates an array of taxonomy related data.
get_current_page_query_params()  : array<string|int, mixed>
Return the current page query parameters.
get_current_query_object_ids()  : array<string|int, mixed>
Catch the current query parameters but load all posts.
get_default_excluded_terms()  : array<string|int, mixed>
Get the list of default excluded terms that should not be displayed inside filters.
get_terms_from_attribute()  : mixed
include_variations_in_counts()  : void
Include variations in counts.
is_or_logic_enabled()  : bool
Determine if the "OR" logic is enabled.
is_reserved_slug()  : bool
Determine if the given slug is reserved by WordPress.
is_taxonomy_page()  : bool
Determine if we're on a product taxonomy page.
is_using_fallback_mode()  : bool
Helper function to determine if fallback mode is enabled or not.
order_numerical_collection()  : Collection
Sort collection by the display value.
query_has_product_post_type()  : bool
Determine if the query's `post_type` argument is using one of the allowed post types.
set_additional_attributes()  : Collection
Forcefully inject additional attributes to instances of filters by passing an key => value array.
should_exclude_variations_from_counts()  : bool
Determine if variations should be excluded from counts.

Methods

array_remove_empty()

Recursively remove empty values for an array.

public static array_remove_empty(array<string|int, mixed> $haystack) : array<string|int, mixed>
Parameters
$haystack : array<string|int, mixed>
Return values
array<string|int, mixed>

calculate_max_price()

Find the highest price indexed and save it into the database.

public static calculate_max_price(Filter $filter) : mixed
Parameters
$filter : Filter
Return values
mixed

custom_field_exists()

Determines if a given custom field exists.

public static custom_field_exists(string $meta_key) : bool
Parameters
$meta_key : string
Return values
bool

filter_visible_terms()

Filter the list of terms to only include the ones that are used as variations for the current product.

public static filter_visible_terms(array<string|int, mixed> $terms, WC_Product $product) : array<string|int, mixed>
Parameters
$terms : array<string|int, mixed>
$product : WC_Product
Return values
array<string|int, mixed>

flatten_results()

Flatten the collection of results and return only the post_id.

public static flatten_results(array<string|int, mixed>|Collection $results) : array<string|int, mixed>

Usually used after the search query has been built.

Parameters
$results : array<string|int, mixed>|Collection
Return values
array<string|int, mixed>

generate_child_filters()

Generate child filters for an attribute type of filter.

public static generate_child_filters(Attribute $filter, array<string|int, mixed> $groups) : void
Parameters
$filter : Attribute
$groups : array<string|int, mixed>
Return values
void

generate_ranged_taxonomy_index_data()

Helper function that generates an array of taxonomy related data.

public static generate_ranged_taxonomy_index_data(array<string|int, mixed> $defaults, string $post_id, string $taxonomy) : array<string|int, mixed>

Data is then processed and terms without numbers in their name are removed from the list.

Parameters
$defaults : array<string|int, mixed>
$post_id : string
$taxonomy : string
Return values
array<string|int, mixed>

generate_taxonomy_index_data()

Helper function that generates an array of taxonomy related data.

public static generate_taxonomy_index_data(array<string|int, mixed> $defaults, string $post_id, string $taxonomy) : array<string|int, mixed>

The function has been abstracted here because we have multiple type of filters that generate the same type of data (but in a slightly different way).

Parameters
$defaults : array<string|int, mixed>
$post_id : string
$taxonomy : string
Return values
array<string|int, mixed>

get_current_page_query_params()

Return the current page query parameters.

public static get_current_page_query_params() : array<string|int, mixed>

If the permalink structure is not "plain" then we return an empty array.

This is used to generate redirects when the user changes the filters or resets them.

Return values
array<string|int, mixed>

get_current_query_object_ids()

Catch the current query parameters but load all posts.

public static get_current_query_object_ids() : array<string|int, mixed>
Return values
array<string|int, mixed>

get_default_excluded_terms()

Get the list of default excluded terms that should not be displayed inside filters.

public static get_default_excluded_terms(string $taxonomy) : array<string|int, mixed>
Parameters
$taxonomy : string
Return values
array<string|int, mixed>

get_terms_from_attribute()

public static get_terms_from_attribute(mixed $variation_id, mixed $taxonomy) : mixed
Parameters
$variation_id : mixed
$taxonomy : mixed
Return values
mixed

include_variations_in_counts()

Include variations in counts.

public static include_variations_in_counts() : void

This is used to override the default behavior of excluding variations from counts.

Return values
void

is_or_logic_enabled()

Determine if the "OR" logic is enabled.

public static is_or_logic_enabled() : bool
Return values
bool

is_reserved_slug()

Determine if the given slug is reserved by WordPress.

public static is_reserved_slug(string $slug) : bool
Parameters
$slug : string

the slug to check.

Return values
bool

true if the slug is reserved, false otherwise.

is_taxonomy_page()

Determine if we're on a product taxonomy page.

public static is_taxonomy_page() : bool
Return values
bool

is_using_fallback_mode()

Helper function to determine if fallback mode is enabled or not.

public static is_using_fallback_mode() : bool
Return values
bool

order_numerical_collection()

Sort collection by the display value.

public static order_numerical_collection(Collection $items) : Collection
Parameters
$items : Collection
Return values
Collection

query_has_product_post_type()

Determine if the query's `post_type` argument is using one of the allowed post types.

public static query_has_product_post_type(WP_Query $query) : bool

We check for the product_variation post type too due to some of the integrations that we provide.

Parameters
$query : WP_Query
Return values
bool

set_additional_attributes()

Forcefully inject additional attributes to instances of filters by passing an key => value array.

public static set_additional_attributes(Collection $filters, array<string|int, mixed>|bool $config) : Collection
Parameters
$filters : Collection

the filters for which new attributes will be injected.

$config : array<string|int, mixed>|bool

when an array, inject it as attributes.

Return values
Collection

should_exclude_variations_from_counts()

Determine if variations should be excluded from counts.

public static should_exclude_variations_from_counts() : bool
Return values
bool

Search results