Automattic\WooCommerce\Internal\RestApi\Routes\V4\Orders\Schema
OrderItemSchema::get_item_response
Get an item response.
Метод класса: OrderItemSchema{}
Хуков нет.
Возвращает
Массив.
Использование
$OrderItemSchema = new OrderItemSchema(); $OrderItemSchema->get_item_response( $order_item, $request, $include_fields ): array;
- $order_item(WC_Order_Item_Product) (обязательный)
- Order item instance.
- $request(WP_REST_Request) (обязательный)
- Request object.
- $include_fields(массив)
- Fields to include in the response.
По умолчанию:array()
Код OrderItemSchema::get_item_response() OrderItemSchema::get item response WC 10.5.2
public function get_item_response( $order_item, WP_REST_Request $request, array $include_fields = array() ): array {
$dp = is_null( $request['num_decimals'] ) ? wc_get_price_decimals() : absint( $request['num_decimals'] );
$quantity_amount = (float) $order_item->get_quantity();
$data = array(
'id' => $order_item->get_id(),
'name' => $order_item->get_name(),
'image' => $this->get_image( $order_item ),
'product_id' => $order_item->get_variation_id() ? $order_item->get_variation_id() : $order_item->get_product_id(),
'product_data' => $this->get_product_data( $order_item ),
'quantity' => $order_item->get_quantity(),
'price' => $quantity_amount ? $order_item->get_total() / $quantity_amount : 0,
'tax_class' => $order_item->get_tax_class(),
'subtotal' => wc_format_decimal( $order_item->get_subtotal(), $dp ),
'subtotal_tax' => wc_format_decimal( $order_item->get_subtotal_tax(), $dp ),
'total' => wc_format_decimal( $order_item->get_total(), $dp ),
'total_tax' => wc_format_decimal( $order_item->get_total_tax(), $dp ),
'taxes' => $this->prepare_taxes( $order_item, $request ),
'meta_data' => $this->prepare_meta_data( $order_item ),
'currency' => $order_item->get_order()->get_currency(),
'currency_symbol' => html_entity_decode( get_woocommerce_currency_symbol( $order_item->get_order()->get_currency() ), ENT_QUOTES ),
);
// Add COGS data.
if ( self::cogs_is_enabled() ) {
$data['cost_of_goods_sold']['total_value'] = isset( $data['cogs_value'] ) ? $data['cogs_value'] : 0;
unset( $data['cogs_value'] );
}
return $data;
}