WC_Admin_Exporters::do_ajax_product_export()
AJAX callback for doing the actual export to the CSV file.
Method of the class: WC_Admin_Exporters{}
Hooks from the method
Return
null
. Nothing (null).
Usage
$WC_Admin_Exporters = new WC_Admin_Exporters(); $WC_Admin_Exporters->do_ajax_product_export();
WC_Admin_Exporters::do_ajax_product_export() WC Admin Exporters::do ajax product export code WC 9.2.3
public function do_ajax_product_export() { check_ajax_referer( 'wc-product-export', 'security' ); if ( ! $this->export_allowed() ) { wp_send_json_error( array( 'message' => __( 'Insufficient privileges to export products.', 'woocommerce' ) ) ); } include_once WC_ABSPATH . 'includes/export/class-wc-product-csv-exporter.php'; $step = isset( $_POST['step'] ) ? absint( $_POST['step'] ) : 1; // WPCS: input var ok, sanitization ok. $exporter = new WC_Product_CSV_Exporter(); if ( ! empty( $_POST['columns'] ) ) { // WPCS: input var ok. $exporter->set_column_names( wp_unslash( $_POST['columns'] ) ); // WPCS: input var ok, sanitization ok. } if ( ! empty( $_POST['selected_columns'] ) ) { // WPCS: input var ok. $exporter->set_columns_to_export( wp_unslash( $_POST['selected_columns'] ) ); // WPCS: input var ok, sanitization ok. } if ( ! empty( $_POST['export_meta'] ) ) { // WPCS: input var ok. $exporter->enable_meta_export( true ); } if ( ! empty( $_POST['export_types'] ) ) { // WPCS: input var ok. $exporter->set_product_types_to_export( wp_unslash( $_POST['export_types'] ) ); // WPCS: input var ok, sanitization ok. } if ( ! empty( $_POST['export_category'] ) && is_array( $_POST['export_category'] ) ) {// WPCS: input var ok. $exporter->set_product_category_to_export( wp_unslash( array_values( $_POST['export_category'] ) ) ); // WPCS: input var ok, sanitization ok. } if ( ! empty( $_POST['filename'] ) ) { // WPCS: input var ok. $exporter->set_filename( wp_unslash( $_POST['filename'] ) ); // WPCS: input var ok, sanitization ok. } $exporter->set_page( $step ); $exporter->generate_file(); $query_args = apply_filters( 'woocommerce_export_get_ajax_query_args', array( 'nonce' => wp_create_nonce( 'product-csv' ), 'action' => 'download_product_csv', 'filename' => $exporter->get_filename(), ) ); if ( 100 === $exporter->get_percent_complete() ) { wp_send_json_success( array( 'step' => 'done', 'percentage' => 100, 'url' => add_query_arg( $query_args, admin_url( 'edit.php?post_type=product&page=product_exporter' ) ), ) ); } else { wp_send_json_success( array( 'step' => ++$step, 'percentage' => $exporter->get_percent_complete(), 'columns' => $exporter->get_column_names(), ) ); } }