问题描述
我已经使用CPT UI插件创建了两个自定义分类法,分别名为Designers(rug_designers)和Product Lines(product_line)。我正在使用内置的WooCommerce导入器工具(不是Product CSV Import Suite)通过CSV将产品导入WooCommerce。我能够按照本指南在使用自动映射的导入中注册“自定义列”,但是,每当我上传CSV文件时,数据就不会保存到自定义分类法中。
* Register the 'Custom Column' column in the importer.
*
* @param array $options
* @return array $options
*/
function add_column_to_importer( $options ) {
// column slug => column name
$options['rug_designers'] = 'Designers';
$options['product_line'] = 'Product Line';
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['Designers'] = 'rug_designers';
$columns['designers'] = 'rug_designers';
$columns['Product Lines'] = 'product_line';
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 ) {
// This appears to be part I am having trouble with,I have even tried it with just the 'rug_designers'
if ( ! empty( $data['rug_designers'] ) || ! empty( $data['product_line'] ) ) {
$object->update_Meta_data( 'rug_designers',$data['rug_designers'] );
$object->update_Meta_data( 'product_line',$data['product_line'] );
}
return $object;
}
正如我在上面的评论中提到的,我认为问题在于流程导入功能。我试图在没有'product_line'代码的情况下运行此程序,但仍然无法在导入csv时让'rug_designers'更新数据。
我非常感谢您的任何建议。谢谢。
解决方法
正在寻找自己解决方案。我使用了CPT UI插件来创建供应商。跟随文档添加列没有问题,但它是将列映射到自定义分类法的问题。希望此评论能解决这个问题并给我们答复。干杯!
,通过购买Woocommerce产品CSV导入套件,我能够完成自定义分类法/帖子类型的导入。它开箱即用,为我省去了从头开始编写代码的大量时间。