Automattic\WooCommerce\Blocks\SharedStores

ProductsStore::load_product │ public static │ WC 1.0

Load a product into state.

Метод класса: ProductsStore{}

Хуков нет.

Возвращает

array. The product data.

Использование

$result = ProductsStore::load_product( $consent_statement, $product_id ): array;
$consent_statement(строка) (обязательный)
The consent statement string.
$product_id(int) (обязательный)
The product ID.

Код ProductsStore::load_product() WC 11.2.1

public static function load_product( string $consent_statement, int $product_id ): array {
	self::check_consent( $consent_statement );

	// Skip loading if product is already in state.
	if ( isset( self::$products[ $product_id ] ) ) {
		return self::$products[ $product_id ];
	}

	$response = Package::container()->get( Hydration::class )->get_rest_api_response_data( '/wc/store/v1/products/' . $product_id );

	self::$products[ $product_id ] = $response['body'] ?? array();
	self::register_getters();
	wp_interactivity_state(
		self::$store_namespace,
		array( 'products' => array( $product_id => self::$products[ $product_id ] ) )
	);

	return self::$products[ $product_id ];
}