Automattic\WooCommerce\StoreApi\Schemas\V1
ShopperListSchema::get_item_response
Serialize the shopper list.
Method of the class: ShopperListSchema{}
No Hooks.
Returns
Array.
Usage
$ShopperListSchema = new ShopperListSchema(); $ShopperListSchema->get_item_response( $shopper_list );
- $shopper_list(ShopperList) (required)
- The list.
ShopperListSchema::get_item_response() ShopperListSchema::get item response code WC 10.9.4
public function get_item_response( $shopper_list ) {
$items = array_values( $shopper_list->get_items() );
$product_ids = array_filter(
array_map(
static function ( ShopperListItem $item ): int {
$variation_id = $item->get_variation_id();
return $variation_id > 0 ? $variation_id : $item->get_product_id();
},
$items
)
);
if ( ! empty( $product_ids ) ) {
_prime_post_caches( array_unique( $product_ids ) );
}
return array(
'slug' => $shopper_list->get_slug(),
'date_created_gmt' => wc_rest_prepare_date_response( $shopper_list->get_date_created_gmt() ),
'item_count' => count( $items ),
'items' => array_values(
array_map(
fn( ShopperListItem $item ) => $this->item_schema->get_item_response( $item ),
$items
)
),
);
}