WC_Product_CSV_Importer_Controller::import
Import the file if it exists and is valid.
Method of the class: WC_Product_CSV_Importer_Controller{}
No Hooks.
Returns
null. Nothing (null).
Usage
$WC_Product_CSV_Importer_Controller = new WC_Product_CSV_Importer_Controller(); $WC_Product_CSV_Importer_Controller->import();
WC_Product_CSV_Importer_Controller::import() WC Product CSV Importer Controller::import code WC 10.4.3
public function import() {
// Displaying this page triggers Ajax action to run the import with a valid nonce,
// therefore this page needs to be nonce protected as well.
check_admin_referer( 'woocommerce-csv-importer' );
self::validate_file_path( $this->file );
if ( ! empty( $_POST['map_from'] ) && ! empty( $_POST['map_to'] ) ) {
$mapping_from = wc_clean( wp_unslash( $_POST['map_from'] ) );
$mapping_to = wc_clean( wp_unslash( $_POST['map_to'] ) );
// Save mapping preferences for future imports.
update_user_option( get_current_user_id(), 'woocommerce_product_import_mapping', $mapping_to );
} else {
wp_redirect( esc_url_raw( $this->get_next_step_link( 'upload' ) ) );
exit;
}
wp_localize_script(
'wc-product-import',
'wc_product_import_params',
array(
'import_nonce' => wp_create_nonce( 'wc-product-import' ),
'mapping' => array(
'from' => $mapping_from,
'to' => $mapping_to,
),
'file' => $this->file,
'update_existing' => $this->update_existing,
'delimiter' => $this->delimiter,
'character_encoding' => $this->character_encoding,
)
);
wp_enqueue_script( 'wc-product-import' );
include_once __DIR__ . '/views/html-csv-import-progress.php';
}