Is it possible to add custom import columns?
-
Hi there,
I added mapping for custom product taxonomies to the import tool according to these instructions:
https://github.com/woocommerce/woocommerce/wiki/Product-CSV-Importer-&-Exporter#adding-custom-import-columns-developersWhen I import my csv the extra columns are shown and automatically mapped to the right fields. But after finishing the import, the new products are added but the custom taxonomies are empty.
Any ideas what could be the problem? thanks
`/**
* Register the ‘Marke’ column in the importer.
*
* @param array $options
* @return array $options
*/
function add_column_to_importer( $options ) {// column slug => column name
$options[‘marke’] = ‘Marke’;return $options;
}
add_filter( ‘woocommerce_csv_product_import_mapping_options’, ‘add_column_to_importer’ );/**
* Add automatic mapping support for ‘Custom Column’.
* This will automatically select the correct mapping for columns named ‘Custom Column’ or ‘custom column’.
*
* @param array $columns
* @return array $columns
*/
function add_column_to_mapping_screen( $columns ) {// potential column name => column slug
$columns[‘Marke’] = ‘marke’;
$columns[‘marke’] = ‘marke’;return $columns;
}
add_filter( ‘woocommerce_csv_product_import_mapping_default_columns’, ‘add_column_to_mapping_screen’ );/**
* Process the data read from the CSV file.
* This just saves the value in meta data, but you can do anything you want here with the data.
*
* @param WC_Product $object – Product being imported or updated.
* @param array $data – CSV data read for the product.
* @return WC_Product $object
*/
function process_import( $object, $data ) {if ( ! empty( $data[‘marke’] ) ) {
$object->update_meta_data( ‘marke’, $data[‘marke’] );
}return $object;
}
add_filter( ‘woocommerce_product_import_pre_insert_product_object’, ‘process_import’, 10, 2 );
- The topic ‘Is it possible to add custom import columns?’ is closed to new replies.