WooCommerce Code Reference

ProductCollectionUtils
in package

Utility methods used for the Product Collection block.

Table of Contents

get_query_vars()  : array<string|int, mixed>
Helper function that constructs a WP_Query args array from a Product Collection or global query.
prepare_and_execute_query()  : mixed
Prepare and execute a query for the Product Collection block.
remove_query_array()  : array<string|int, mixed>
Remove query array from tax or meta query by searching for arrays that contain exact key => value pair.
remove_empty_array_recursive()  : mixed
Remove falsy item from array, recursively.

Methods

get_query_vars()

Helper function that constructs a WP_Query args array from a Product Collection or global query.

public static get_query_vars(WP_Block $block, int $page) : array<string|int, mixed>
Parameters
$block : WP_Block

Block instance.

$page : int

Current query's page.

Return values
array<string|int, mixed>Returns the constructed WP_Query arguments.

prepare_and_execute_query()

Prepare and execute a query for the Product Collection block.

public static prepare_and_execute_query(WP_Block $block) : mixed

This method is used by the Product Collection block and the No Results block.

Parameters
$block : WP_Block

Block instance.

Return values
mixed

remove_query_array()

Remove query array from tax or meta query by searching for arrays that contain exact key => value pair.

public static remove_query_array(array<string|int, mixed> $queries, string $key, mixed $value) : array<string|int, mixed>
Parameters
$queries : array<string|int, mixed>

tax_query or meta_query.

$key : string

Array key to search for.

$value : mixed

Value to compare with search result.

Return values
array<string|int, mixed>

remove_empty_array_recursive()

Remove falsy item from array, recursively.

private static remove_empty_array_recursive(array<string|int, mixed> $array) : mixed
Parameters
$array : array<string|int, mixed>

The input array to filter.

Return values
mixed