WooCommerce Code Reference

Utils
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.
parse_frontend_location_context()  : array<string|int, mixed>
Parse WP Query's front-end context for the Product Collection block.
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.

parse_frontend_location_context()

Parse WP Query's front-end context for the Product Collection block.

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

The sourceData structure depends on the context type as follows:

  • site: [ ]
  • order: [ 'orderId' => int ]
  • cart: [ 'productIds' => int[] ]
  • archive: [ 'taxonomy' => string, 'termId' => int ]
  • product: [ 'productId' => int ]
Return values
array<string|int, mixed>$context { @type string $type The context type. Possible values are 'site', 'order', 'cart', 'archive', 'product'. @type array $sourceData The context source data. Can be the product ID of the viewed product, the order ID of the current order, etc. }

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