WooCommerce Code Reference

ProductQuery
in package

Product Query class.

Helper class to handle product queries for the API.

Table of Contents

add_query_clauses()  : array<string|int, mixed>
Add in conditional search filters for products.
convert_tax_query_to_meta_query()  : array<string|int, mixed>
Convert the tax_query to a meta_query which is needed to support filtering by attributes for variations.
get_last_modified()  : int
Get last modified date for all products.
get_objects()  : array<string|int, mixed>
Get objects.
get_results()  : array<string|int, mixed>
Get results of query.
prepare_objects_query()  : array<string|int, mixed>
Prepare query args to pass to WP_Query for a REST API request.
add_price_filter_clauses()  : array<string|int, mixed>
Add in conditional price 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.
get_price_filter_query_for_displayed_taxes()  : string
Get query for price filters when dealing with displayed taxes.
prepare_price_filter()  : float
Converts price filter from subunits to decimal.

Methods

add_query_clauses()

Add in conditional search filters for products.

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

Query args.

$wp_query : WC_Query

WC_Query object.

Return values
array<string|int, mixed>

convert_tax_query_to_meta_query()

Convert the tax_query to a meta_query which is needed to support filtering by attributes for variations.

public convert_tax_query_to_meta_query(array<string|int, mixed> $tax_query) : array<string|int, mixed>
Parameters
$tax_query : array<string|int, mixed>

The tax_query to convert.

Return values
array<string|int, mixed>

get_objects()

Get objects.

public get_objects(WP_REST_Request $request) : array<string|int, mixed>
Parameters
$request : WP_REST_Request

Request data.

Return values
array<string|int, mixed>

get_results()

Get results of query.

public get_results(WP_REST_Request $request) : array<string|int, mixed>
Parameters
$request : WP_REST_Request

Request data.

Return values
array<string|int, mixed>

prepare_objects_query()

Prepare query args to pass to WP_Query for a REST API request.

public prepare_objects_query(WP_REST_Request $request) : array<string|int, mixed>
Parameters
$request : WP_REST_Request

Request data.

Return values
array<string|int, mixed>

add_price_filter_clauses()

Add in conditional price filters.

protected add_price_filter_clauses(array<string|int, mixed> $args, WC_Query $wp_query) : array<string|int, mixed>
Parameters
$args : array<string|int, mixed>

Query args.

$wp_query : WC_Query

WC_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.

protected 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.

protected 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.

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

SQL join.

Return values
string

get_price_filter_query_for_displayed_taxes()

Get query for price filters when dealing with displayed taxes.

protected 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.

prepare_price_filter()

Converts price filter from subunits to decimal.

protected prepare_price_filter(string|int $price_filter) : float
Parameters
$price_filter : string|int

Raw price filter in subunit format.

Return values
floatPrice filter in decimal format.