Table_Query

Responsible for managing the product table query, retrieving the list of products (as an array of WP_Post objects), and finding the product totals.

Tags
author

Barn2 Plugins support@barn2.com

license

GPL-3.0

copyright

Barn2 Media Ltd

Table of Contents

$args  : mixed
$products  : mixed
$total_filtered_products  : mixed
$total_products  : mixed
__construct()  : mixed
Table_Query constructor.
filter_by_price_post_clauses()  : array<string|int, mixed>
Custom query to filter by price when using the 'Filter by price' widget. Attached to 'posts_clauses' hook.
filter_wp_posts_selected_columns()  : string
Removes unnecessary columns from the table query if we're not displaying the product description or short description.
get_products()  : array<string|int, WC_Product>
Get the list of products for this table query.
get_total_filtered_products()  : int
Get the number of filtered products in this query.
get_total_products()  : int
Get the number of products in this query.
order_by_sku_asc_post_clauses()  : array<string|int, mixed>
Custom query to order by SKU (asc). Attached to 'posts_clauses' hook.
order_by_sku_desc_post_clauses()  : array<string|int, mixed>
Custom query to order by SKU (desc). Attached to 'posts_clauses' hook.
search_by_sku_post_clauses()  : array<string|int, mixed>
Custom query to search by SKU. Attached to 'posts_clauses' hook.
search_by_sku_post_search()  : string
Custom query to search by SKU. Attached to 'posts_search' hook.
set_products()  : mixed
Set the list of products for this table query.
set_total_filtered_products()  : mixed
Set the filtered product total.
set_total_products()  : mixed
Set the product total.
add_ordering_args()  : array<string|int, mixed>
Add the ordering args for our product query.
add_user_search_args()  : mixed
append_product_sorting_table_join()  : string
Join wc_product_meta_lookup to posts table if not already joined.
array_map_prefix_column()  : mixed
build_base_product_query()  : mixed
build_meta_query()  : mixed
build_product_query()  : mixed
build_product_totals_query()  : mixed
build_tax_query()  : mixed
check_within_product_limit()  : mixed
get_query_hooks()  : mixed
get_user_products()  : mixed
get_woocommerce_tax_query()  : array<string|int, mixed>
Get the WooCommerce tax query. This is similar to WC_Query::get_tax_query but with a few alterations needed for our product tables.
is_lazy_load_search_by_sku()  : bool
Are we searching by SKU in a lazy loaded table?
is_lazy_load_sort_by_numeric_sku()  : bool
Are we sorting by numeric SKU in a lazy loaded table?
maybe_add_relation()  : mixed
run_product_query()  : WP_Query
Run the product query with the specified query args.
tax_query_item()  : array<string|int, mixed>
Generate an inner array for the 'tax_query' arg in WP_Query.

Properties

$total_filtered_products

private mixed $total_filtered_products = null

$total_products

private mixed $total_products = null

Methods

__construct()

Table_Query constructor.

public __construct(Table_Args $args) : mixed
Parameters
$args : Table_Args

The table args.

Return values
mixed

filter_by_price_post_clauses()

Custom query to filter by price when using the 'Filter by price' widget. Attached to 'posts_clauses' hook.

public filter_by_price_post_clauses(array<string|int, mixed> $args) : array<string|int, mixed>

This is basically a copy of WC_Query::price_filter_post_clauses but without the check for is_main_query.

Parameters
$args : array<string|int, mixed>

The post clauses args.

Return values
array<string|int, mixed>

The filtered args.

filter_wp_posts_selected_columns()

Removes unnecessary columns from the table query if we're not displaying the product description or short description.

public filter_wp_posts_selected_columns(string $fields) : string
Parameters
$fields : string

The posts table column selection.

Return values
string

The updated column selection.

get_products()

Get the list of products for this table query.

public get_products() : array<string|int, WC_Product>
Return values
array<string|int, WC_Product>

An array of WC_Product objects.

get_total_filtered_products()

Get the number of filtered products in this query.

public get_total_filtered_products() : int

Will be the same as the overall total (get_total_products) if there is no filtering applied.

Return values
int

The filtered total.

get_total_products()

Get the number of products in this query.

public get_total_products() : int
Return values
int

The product total.

order_by_sku_asc_post_clauses()

Custom query to order by SKU (asc). Attached to 'posts_clauses' hook.

public order_by_sku_asc_post_clauses(array<string|int, mixed> $args) : array<string|int, mixed>

Based on WC_Admin_List_Table_Products::order_by_sku_asc_post_clauses.

Parameters
$args : array<string|int, mixed>

The post clauses args.

Return values
array<string|int, mixed>

The filtered args.

order_by_sku_desc_post_clauses()

Custom query to order by SKU (desc). Attached to 'posts_clauses' hook.

public order_by_sku_desc_post_clauses(array<string|int, mixed> $args) : array<string|int, mixed>

Based on WC_Admin_List_Table_Products::order_by_sku_desc_post_clauses.

Parameters
$args : array<string|int, mixed>

The post clauses args.

Return values
array<string|int, mixed>

The filtered args.

search_by_sku_post_clauses()

Custom query to search by SKU. Attached to 'posts_clauses' hook.

public search_by_sku_post_clauses(array<string|int, mixed> $args) : array<string|int, mixed>
Parameters
$args : array<string|int, mixed>

The post clauses args.

Return values
array<string|int, mixed>

The filtered args.

search_by_sku_post_search()

Custom query to search by SKU. Attached to 'posts_search' hook.

public search_by_sku_post_search(string $search) : string
Parameters
$search : string

The posts search SQL query.

Return values
string

The filtered SQL.

set_products()

Set the list of products for this table query.

public set_products(mixed $products) : mixed
Parameters
$products : mixed
Return values
mixed

set_total_filtered_products()

Set the filtered product total.

public set_total_filtered_products(mixed $total_filtered_products) : mixed
Parameters
$total_filtered_products : mixed
Return values
mixed

set_total_products()

Set the product total.

public set_total_products(mixed $total_products) : mixed
Parameters
$total_products : mixed
Return values
mixed

add_ordering_args()

Add the ordering args for our product query.

private add_ordering_args(array<string|int, mixed> $query_args) : array<string|int, mixed>

For standard loading, DataTables will re-sort the results if the sort column is present in table.

Parameters
$query_args : array<string|int, mixed>

The query args.

Return values
array<string|int, mixed>

The updated query args.

add_user_search_args()

private add_user_search_args(array<string|int, mixed> $query_args) : mixed
Parameters
$query_args : array<string|int, mixed>
Return values
mixed

append_product_sorting_table_join()

Join wc_product_meta_lookup to posts table if not already joined.

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

SQL join.

Return values
string

The updated SQL join.

array_map_prefix_column()

private array_map_prefix_column(mixed $n) : mixed
Parameters
$n : mixed
Return values
mixed

build_base_product_query()

private build_base_product_query() : mixed
Return values
mixed

build_meta_query()

private build_meta_query() : mixed
Return values
mixed

build_product_query()

private build_product_query() : mixed
Return values
mixed

build_product_totals_query()

private build_product_totals_query() : mixed
Return values
mixed

build_tax_query()

private build_tax_query() : mixed
Return values
mixed

check_within_product_limit()

private check_within_product_limit(mixed $count) : mixed
Parameters
$count : mixed
Return values
mixed

get_query_hooks()

private get_query_hooks() : mixed
Return values
mixed

get_user_products()

private get_user_products() : mixed
Return values
mixed

get_woocommerce_tax_query()

Get the WooCommerce tax query. This is similar to WC_Query::get_tax_query but with a few alterations needed for our product tables.

private get_woocommerce_tax_query() : array<string|int, mixed>
Return values
array<string|int, mixed>

The WooCommerce tax query.

is_lazy_load_search_by_sku()

Are we searching by SKU in a lazy loaded table?

private is_lazy_load_search_by_sku() : bool
Return values
bool

true if SKU search + lazy load.

is_lazy_load_sort_by_numeric_sku()

Are we sorting by numeric SKU in a lazy loaded table?

private is_lazy_load_sort_by_numeric_sku() : bool
Return values
bool

true if SKU sort + SKUs are numeric + lazy load.

maybe_add_relation()

private maybe_add_relation(mixed $query[, mixed $relation = 'AND' ]) : mixed
Parameters
$query : mixed
$relation : mixed = 'AND'
Return values
mixed

run_product_query()

Run the product query with the specified query args.

private run_product_query(array<string|int, mixed> $query_args) : WP_Query
Parameters
$query_args : array<string|int, mixed>

The query args to pass to WP_Query.

Return values
WP_Query

The query object.

tax_query_item()

Generate an inner array for the 'tax_query' arg in WP_Query.

private tax_query_item(string|array<string|int, mixed> $terms, string $taxonomy[, string $operator = 'IN' ][, string $field = '' ]) : array<string|int, mixed>
Parameters
$terms : string|array<string|int, mixed>

The list of terms as a string.

$taxonomy : string

The taxonomy name.

$operator : string = 'IN'

The SQL operator: IN, NOT IN, AND, etc.

$field : string = ''

Add the tax query by term_id or slug. Leave empty to auto-detect correct type.

Return values
array<string|int, mixed>

The completed tax query.

Search results