Automattic\WooCommerce\StoreApi\Schemas\V1
ShopperListItemSchema::get_item_response
Serialize the saved item.
Method of the class: ShopperListItemSchema{}
No Hooks.
Returns
Array.
Usage
$ShopperListItemSchema = new ShopperListItemSchema(); $ShopperListItemSchema->get_item_response( $item );
- $item(ShopperListItem) (required)
- Saved item.
ShopperListItemSchema::get_item_response() ShopperListItemSchema::get item response code WC 10.9.4
public function get_item_response( $item ) {
$variation_id = $item->get_variation_id();
$product_id = $variation_id > 0 ? $variation_id : $item->get_product_id();
$product = $item->get_product();
$is_live = $item->is_live();
$response = array(
'key' => $item->get_key(),
'id' => $product_id,
'product_id' => $item->get_product_id(),
'variation_id' => $variation_id,
'quantity' => $item->get_quantity(),
'is_live' => $is_live,
'is_purchasable' => $item->is_purchasable(),
'date_added_gmt' => wc_rest_prepare_date_response( $item->get_date_added_gmt() ),
);
if ( $is_live && $product instanceof \WC_Product ) {
$response['name'] = $this->get_name( $product );
$response['permalink'] = $product->get_permalink();
$response['images'] = $this->get_images( $product );
$response['variation'] = $this->format_variation_data( $item->get_variation_attributes(), $product );
$response['prices'] = (object) $this->get_prices( $product );
$response['price_html'] = (string) $product->get_price_html();
$response['image_html'] = $this->get_image_html( $product );
} else {
$response['name'] = $this->prepare_html_response( $item->get_product_title_at_save() );
$response['permalink'] = null;
$response['images'] = array();
$response['variation'] = array();
$response['prices'] = null;
$response['price_html'] = '';
$response['image_html'] = $this->get_image_html( null );
}
return $response;
}