WC_Product_CSV_Importer::set_parsed_data
Map and format raw data to known fields.
Method of the class: WC_Product_CSV_Importer{}
Hooks from the method
Returns
null. Nothing (null).
Usage
// protected - for code of main (parent) or child class $result = $this->set_parsed_data();
WC_Product_CSV_Importer::set_parsed_data() WC Product CSV Importer::set parsed data code WC 10.5.0
protected function set_parsed_data() {
$parse_functions = $this->get_formatting_callback();
$mapped_keys = $this->get_mapped_keys();
$use_mb = function_exists( 'mb_convert_encoding' );
// Parse the data.
foreach ( $this->raw_data as $row_index => $row ) {
// Skip empty rows.
if ( ! count( array_filter( $row ) ) ) {
continue;
}
$this->parsing_raw_data_index = $row_index;
$data = array();
do_action( 'woocommerce_product_importer_before_set_parsed_data', $row, $mapped_keys );
foreach ( $row as $id => $value ) {
// Skip ignored columns.
if ( empty( $mapped_keys[ $id ] ) ) {
continue;
}
// Convert UTF8.
if ( $use_mb ) {
$encoding = mb_detect_encoding( $value, mb_detect_order(), true );
if ( $encoding ) {
$value = mb_convert_encoding( $value, 'UTF-8', $encoding );
} else {
$value = mb_convert_encoding( $value, 'UTF-8', 'UTF-8' );
}
} else {
$value = wp_check_invalid_utf8( $value, true );
}
$data[ $mapped_keys[ $id ] ] = call_user_func( $parse_functions[ $id ], $value );
}
/**
* Filter product importer parsed data.
*
* @param array $parsed_data Parsed data.
* @param WC_Product_Importer $importer Importer instance.
*
* @since
*/
$this->parsed_data[] = apply_filters( 'woocommerce_product_importer_parsed_data', $this->expand_data( $data ), $this );
}
}