Automattic\WooCommerce\Admin\API\Reports\Export
Controller::export_items()
Export data based on user request params.
Метод класса: Controller{}
Хуки из метода
Возвращает
WP_Error|WP_REST_Response
.
Использование
$Controller = new Controller(); $Controller->export_items( $request );
- $request(WP_REST_Request) (обязательный)
- Request data.
Код Controller::export_items() Controller::export items WC 9.3.3
public function export_items( $request ) { $report_type = $request['type']; $report_args = empty( $request['report_args'] ) ? array() : $request['report_args']; $send_email = isset( $request['email'] ) ? $request['email'] : false; $default_export_id = str_replace( '.', '', microtime( true ) ); $export_id = apply_filters( 'woocommerce_admin_export_id', $default_export_id ); $export_id = (string) sanitize_file_name( $export_id ); $total_rows = ReportExporter::queue_report_export( $export_id, $report_type, $report_args, $send_email ); if ( 0 === $total_rows ) { return rest_ensure_response( array( 'message' => __( 'There is no data to export for the given request.', 'woocommerce' ), ) ); } ReportExporter::update_export_percentage_complete( $report_type, $export_id, 0 ); $response = rest_ensure_response( array( 'message' => __( 'Your report file is being generated.', 'woocommerce' ), 'export_id' => $export_id, ) ); // Include a link to the export status endpoint. $response->add_links( array( 'status' => array( 'href' => rest_url( sprintf( '%s/reports/%s/export/%s/status', $this->namespace, $report_type, $export_id ) ), ), ) ); $data = $this->prepare_response_for_collection( $response ); return rest_ensure_response( $data ); }