diff --git a/includes/import/class-wc-product-csv-importer.php b/includes/import/class-wc-product-csv-importer.php index 91819de3543..97c97ba19e8 100644 --- a/includes/import/class-wc-product-csv-importer.php +++ b/includes/import/class-wc-product-csv-importer.php @@ -222,11 +222,16 @@ class WC_Product_CSV_Importer extends WC_Product_Importer { '/Download * URL/' => 'esc_url', ); - $headers = ! empty( $this->mapped_keys ) ? $this->mapped_keys : $this->raw_keys; - $parse_functions = array(); + $parse_functions = array(); + $this->parsed_data = array(); + + // If we have no mapped data, abort. + if ( empty( $this->mapped_keys ) ) { + return; + } // Figure out the parse function for each column. - foreach ( $headers as $index => $heading ) { + foreach ( $this->mapped_keys as $index => $heading ) { $parse_function = 'esc_attr'; if ( isset( $data_formatting[ $heading ] ) ) { @@ -247,7 +252,7 @@ class WC_Product_CSV_Importer extends WC_Product_Importer { foreach ( $this->raw_data as $row ) { $item = array(); foreach ( $row as $index => $field ) { - $item[ $headers[ $index ] ] = call_user_func( $parse_functions[ $index ], $field ); + $item[ $this->mapped_keys[ $index ] ] = call_user_func( $parse_functions[ $index ], $field ); } $this->parsed_data[] = $item; }