WooCommerce Code Reference

ProductsStore
in package

Manages the registration of interactivity state that provides product data to interactive blocks. This is shared store data that is not tied to one specific block.

This is an experimental API and may change in future versions.

Table of Contents

$consent_statement  : string
The consent statement for using this experimental API.
$product_variations  : array<string|int, mixed>
Product variations that have been loaded into state.
$products  : array<string|int, mixed>
Products that have been loaded into state.
$store_namespace  : string
The namespace for the store.
load_product()  : array<string|int, mixed>
Load a product into state.
load_purchasable_child_products()  : array<string|int, mixed>
Load all purchasable child products of a parent product into state.
load_variations()  : array<string|int, mixed>
Load all variations of a variable product into state.
check_consent()  : true
Check that the consent statement was passed.
register_state()  : void
Register the interactivity state if products have been loaded.

Properties

The consent statement for using this experimental API.

private static string $consent_statement = 'I acknowledge that using experimental APIs means my theme or plugin will inevitably break in the next version of WooCommerce'

Methods

load_product()

Load a product into state.

public static load_product(string $consent_statement, int $product_id) : array<string|int, mixed>
Parameters
$consent_statement : string

The consent statement string.

$product_id : int

The product ID.

Tags
throws
InvalidArgumentException

If consent statement doesn't match.

Return values
array<string|int, mixed>The product data.

load_purchasable_child_products()

Load all purchasable child products of a parent product into state.

public static load_purchasable_child_products(string $consent_statement, int $parent_id) : array<string|int, mixed>
Parameters
$consent_statement : string

The consent statement string.

$parent_id : int

The parent product ID.

Tags
throws
InvalidArgumentException

If consent statement doesn't match.

Return values
array<string|int, mixed>The purchasable child products keyed by ID.

load_variations()

Load all variations of a variable product into state.

public static load_variations(string $consent_statement, int $parent_id) : array<string|int, mixed>
Parameters
$consent_statement : string

The consent statement string.

$parent_id : int

The parent product ID.

Tags
throws
InvalidArgumentException

If consent statement doesn't match.

Return values
array<string|int, mixed>The variations keyed by ID.

Check that the consent statement was passed.

private static check_consent(string $consent_statement) : true
Parameters
$consent_statement : string

The consent statement string.

Tags
throws
InvalidArgumentException

If the statement does not match.

Return values
true