WooCommerce Code Reference

QueryFilters
in package

Process the query data for filtering purposes.

Table of Contents

add_query_clauses()  : array<string|int, mixed>
Add conditional query clauses based on the filter params in query vars.
get_attribute_counts()  : array<string|int, mixed>
Get attribute counts for the current products.
get_filtered_price()  : object
Get price data for current products.
get_rating_counts()  : array<string|int, mixed>
Get rating counts for the current products.
get_stock_status_counts()  : array<string|int, mixed>
Get stock status counts for the current products.
main_query_filter()  : array<string|int, mixed>
Filter the posts clauses of the main query to suport global filters.
adjust_price_filter_for_tax_class()  : float
Adjusts a price filter based on a tax class and whether or not the amount includes or excludes taxes.
adjust_price_filters_for_displayed_taxes()  : bool
If price filters need adjustment to work with displayed taxes, this returns true.
append_product_sorting_table_join()  : string
Join wc_product_meta_lookup to posts if not already joined.
attribute_filter_clauses()  : array<string|int, mixed>
Add query clauses for attribute filter.
generate_stock_status_count_query()  : false|string
Generate calculate query by stock status.
get_chosen_attributes()  : array<string|int, mixed>
Get an array of attributes and terms selected from query arguments.
get_lookup_table_name()  : string
Get attribute lookup table name.
get_price_filter_query_for_displayed_taxes()  : string
Get query for price filters when dealing with displayed taxes.
price_filter_clauses()  : array<string|int, mixed>
Add query clauses for price filter.
stock_filter_clauses()  : array<string|int, mixed>
Add query clauses for stock filter.

Methods

add_query_clauses()

Add conditional query clauses based on the filter params in query vars.

public add_query_clauses(array<string|int, mixed> $args, WP_Query $wp_query) : array<string|int, mixed>
Parameters
$args : array<string|int, mixed>

Query args.

$wp_query : WP_Query

WP_Query object.

Return values
array<string|int, mixed>

get_attribute_counts()

Get attribute counts for the current products.

public get_attribute_counts(array<string|int, mixed> $query_vars, string $attribute_to_count) : array<string|int, mixed>
Parameters
$query_vars : array<string|int, mixed>

The WP_Query arguments.

$attribute_to_count : string

Attribute taxonomy name.

Return values
array<string|int, mixed>termId=>count pairs.

get_filtered_price()

Get price data for current products.

public get_filtered_price(array<string|int, mixed> $query_vars) : object
Parameters
$query_vars : array<string|int, mixed>

The WP_Query arguments.

Return values
object

get_rating_counts()

Get rating counts for the current products.

public get_rating_counts(array<string|int, mixed> $query_vars) : array<string|int, mixed>
Parameters
$query_vars : array<string|int, mixed>

The WP_Query arguments.

Return values
array<string|int, mixed>rating=>count pairs.

get_stock_status_counts()

Get stock status counts for the current products.

public get_stock_status_counts(array<string|int, mixed> $query_vars) : array<string|int, mixed>
Parameters
$query_vars : array<string|int, mixed>

The WP_Query arguments.

Return values
array<string|int, mixed>status=>count pairs.

main_query_filter()

Filter the posts clauses of the main query to suport global filters.

public main_query_filter(array<string|int, mixed> $args, WP_Query $wp_query) : array<string|int, mixed>
Parameters
$args : array<string|int, mixed>

Query args.

$wp_query : WP_Query

WP_Query object.

Return values
array<string|int, mixed>

adjust_price_filter_for_tax_class()

Adjusts a price filter based on a tax class and whether or not the amount includes or excludes taxes.

private adjust_price_filter_for_tax_class(float $price_filter, string $tax_class) : float

This calculation logic is based on wc_get_price_excluding_tax and wc_get_price_including_tax in core.

Parameters
$price_filter : float

Price filter amount as entered.

$tax_class : string

Tax class for adjustment.

Return values
float

adjust_price_filters_for_displayed_taxes()

If price filters need adjustment to work with displayed taxes, this returns true.

private adjust_price_filters_for_displayed_taxes() : bool

This logic is used when prices are stored in the database differently to how they are being displayed, with regards to taxes.

Return values
bool

append_product_sorting_table_join()

Join wc_product_meta_lookup to posts if not already joined.

private append_product_sorting_table_join(string $sql) : string
Parameters
$sql : string

SQL join.

Return values
string

attribute_filter_clauses()

Add query clauses for attribute filter.

private attribute_filter_clauses(array<string|int, mixed> $args, WP_Query $wp_query) : array<string|int, mixed>
Parameters
$args : array<string|int, mixed>

Query args.

$wp_query : WP_Query

WP_Query object.

Return values
array<string|int, mixed>

generate_stock_status_count_query()

Generate calculate query by stock status.

private generate_stock_status_count_query(string $status, string $product_query_sql, array<string|int, mixed> $stock_status_options) : false|string
Parameters
$status : string

status to calculate.

$product_query_sql : string

product query for current filter state.

$stock_status_options : array<string|int, mixed>

available stock status options.

Return values
false|string

get_chosen_attributes()

Get an array of attributes and terms selected from query arguments.

private get_chosen_attributes(array<string|int, mixed> $query_vars) : array<string|int, mixed>
Parameters
$query_vars : array<string|int, mixed>

The WP_Query arguments.

Return values
array<string|int, mixed>

get_lookup_table_name()

Get attribute lookup table name.

private get_lookup_table_name() : string
Return values
string

get_price_filter_query_for_displayed_taxes()

Get query for price filters when dealing with displayed taxes.

private get_price_filter_query_for_displayed_taxes(float $price_filter[, string $column = 'min_price' ][, string $operator = '>=' ]) : string
Parameters
$price_filter : float

Price filter to apply.

$column : string = 'min_price'

Price being filtered (min or max).

$operator : string = '>='

Comparison operator for column.

Return values
stringConstructed query.

price_filter_clauses()

Add query clauses for price filter.

private price_filter_clauses(array<string|int, mixed> $args, WP_Query $wp_query) : array<string|int, mixed>
Parameters
$args : array<string|int, mixed>

Query args.

$wp_query : WP_Query

WP_Query object.

Return values
array<string|int, mixed>

stock_filter_clauses()

Add query clauses for stock filter.

private stock_filter_clauses(array<string|int, mixed> $args, WP_Query $wp_query) : array<string|int, mixed>
Parameters
$args : array<string|int, mixed>

Query args.

$wp_query : WP_Query

WP_Query object.

Return values
array<string|int, mixed>