我无法在csv产品中导入自定义分类法。
这是我的代码。请任何人对此进行审查并解决此问题。
/**
* Register the 'Custom Column' column in the importer.
*/
function add_column_to_importer( $options ) {
// column slug => column name
$options['brand'] = 'Brands';
return $options;
}
add_filter( 'woocommerce_csv_product_import_mapping_options', 'add_column_to_importer' );
/**
* Add automatic mapping support for 'Custom Column'.
*/
function add_column_to_mapping_screen( $columns ) {
// potential column name => column slug
$columns['Brands'] = 'brand';
$columns['brand'] = 'brand';
return $columns;
}
add_filter( 'woocommerce_csv_product_import_mapping_default_columns', 'add_column_to_mapping_screen' );
/**
* Process the data read from the CSV file.
*/
function process_import( $object, $data ) {
if ( ! empty( $data['brand'] ) ) {
$object->update_meta_data( 'brand', $data['brand'] );
}
return $object;
}
add_filter( 'woocommerce_product_import_pre_insert_product_object', 'process_import', 10, 2 );