【发布时间】:2018-02-25 23:17:13
【问题描述】:
从 WooCommerce 3.x 开始,现在有了原生品牌支持。但是,品牌不是产品默认导入/导出功能的一部分。我在 import/export 中找到了有关如何添加自定义列的文档:
/**
* Add the custom column to the exporter and the exporter column menu.
*
* @param array $columns
* @return array $columns
*/
function add_export_column( $columns ) {
// column slug => column name
$columns['custom_column'] = 'Custom Column';
return $columns;
}
add_filter( 'woocommerce_product_export_column_names', 'add_export_column' );
add_filter( 'woocommerce_product_export_product_default_columns', 'add_export_column' );
/**
* Provide the data to be exported for one item in the column.
*
* @param mixed $value (default: '')
* @param WC_Product $product
* @return mixed $value - Should be in a format that can be output into a text file (string, numeric, etc).
*/
function add_export_data( $value, $product ) {
$value = $product->get_meta( 'custom_column', true, 'edit' );
return $value;
}
// Filter you want to hook into will be: 'woocommerce_product_export_product_column_{$column_slug}'.
add_filter( 'woocommerce_product_export_product_column_custom_column', 'add_export_data', 10, 2 );
使用$product->get_meta( 'brands', true, 'edit' ); 没有成功。如何将品牌添加到导入/导出?
更新: 我做了什么来解决这个问题.. - 将品牌移动到“标签”列 - 在管理员上,按标签批量编辑产品,并标记相应的列。
【问题讨论】:
标签: php wordpress import woocommerce