Automattic\WooCommerce\Admin\API
MarketingCampaigns::prepare_item_for_response()
Prepares the item for the REST response.
Метод класса: MarketingCampaigns{}
Хуков нет.
Возвращает
WP_REST_Response|WP_Error
. Response object on success, or WP_Error object on failure.
Использование
$MarketingCampaigns = new MarketingCampaigns(); $MarketingCampaigns->prepare_item_for_response( $item, $request );
- $item(MarketingCampaign) (обязательный)
- WordPress representation of the item.
- $request(WP_REST_Request) (обязательный)
- Request object.
Код MarketingCampaigns::prepare_item_for_response() MarketingCampaigns::prepare item for response WC 9.3.3
public function prepare_item_for_response( $item, $request ) { $data = array( 'id' => $item->get_id(), 'channel' => $item->get_type()->get_channel()->get_slug(), 'title' => $item->get_title(), 'manage_url' => $item->get_manage_url(), ); if ( $item->get_cost() instanceof Price ) { $data['cost'] = array( 'value' => wc_format_decimal( $item->get_cost()->get_value() ), 'currency' => $item->get_cost()->get_currency(), 'formatted' => $this->get_formatted_price( $item->get_cost() ), ); } if ( $item->get_sales() instanceof Price ) { $data['sales'] = array( 'value' => wc_format_decimal( $item->get_sales()->get_value() ), 'currency' => $item->get_sales()->get_currency(), 'formatted' => $this->get_formatted_price( $item->get_sales() ), ); } $context = $request['context'] ?? 'view'; $data = $this->add_additional_fields_to_object( $data, $request ); $data = $this->filter_response_by_context( $data, $context ); return rest_ensure_response( $data ); }