Php 通过CSV将自定义分类导入WooCommerce
我已经使用名为Designers(地毯设计师)和Productline(产品线)的CPT UI插件创建了两个自定义分类法。我正在使用内置的WooCommerce导入工具(不是产品CSV导入套件)通过CSV将产品导入WooCommerce。我能够按照本指南使用自动映射在导入中注册自定义列,但是,每当我上载CSV文件时,数据不会保存到自定义分类中 下面是我在functions.php文件中的当前代码Php 通过CSV将自定义分类导入WooCommerce,php,wordpress,csv,woocommerce,custom-taxonomy,Php,Wordpress,Csv,Woocommerce,Custom Taxonomy,我已经使用名为Designers(地毯设计师)和Productline(产品线)的CPT UI插件创建了两个自定义分类法。我正在使用内置的WooCommerce导入工具(不是产品CSV导入套件)通过CSV将产品导入WooCommerce。我能够按照本指南使用自动映射在导入中注册自定义列,但是,每当我上载CSV文件时,数据不会保存到自定义分类中 下面是我在functions.php文件中的当前代码 * Register the 'Custom Column' column in the impo
* 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”代码的情况下运行此程序,但仍然无法让“rug_designers”在csv导入时更新数据
如有任何建议,我将不胜感激。谢谢。我自己正在寻找解决方案。我已经使用CPTUI插件创建了供应商。跟踪文档添加列没有问题,但将列映射到自定义分类法才是问题所在。希望这句话能打动这个问题,给我们一个答案。干杯 通过购买Woocommerce产品CSV导入套件,我能够完成自定义分类法/帖子类型的导入。它可以直接工作,并且为我节省了大量的时间,使我可以从头开始编写代码