Automattic\WooCommerce\Blocks\SharedStores
ProductsStore::load_product
Load a product into state.
Method of the class: ProductsStore{}
No Hooks.
Returns
Array. The product data.
Usage
$result = ProductsStore::load_product( $consent_statement, $product_id ): array;
- $consent_statement(string) (required)
- The consent statement string.
- $product_id(int) (required)
- The product ID.
ProductsStore::load_product() ProductsStore::load product code WC 10.7.0
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_state();
return self::$products[ $product_id ];
}