php - Woocommerce 3.x 中的导入和导出产品品牌

标签 php wordpress import woocommerce

自 WooCommerce 3.x 起,现在有了原生品牌支持。但是,品牌不是产品默认导入/导出功能的一部分。我找到了有关如何在导入/导出中添加自定义列的文档:

/**
 * 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' ); 不起作用。如何将品牌添加到导入/导出中?

更新: 我做了什么来解决这个问题.. - 将品牌移至“标签”列 - 在管理上,按标签批量编辑产品,并标记相应的列。

最佳答案

我一直在使用 Ultimate Brands 插件,并且也认为必须有一种通过 CSV 更新自定义分类值的方法。我设法使用 Woocommerce 产品 CSV 导入套件导入品牌名称,但尚未找到通过内置导出器的 Woocommerce 导出的方法。作为一名开发人员,我认为这一定与“get_terms”函数有关。我已经尝试了很多变体,但还没有运气。我认为它应该看起来像这样,但还没有成功:

function add_export_data() {
        $product_id = $post->ID;
        $value =  get_terms($product_id, 'product_brand');      
        return $value;
} 

关于php - Woocommerce 3.x 中的导入和导出产品品牌,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46262005/

相关文章:

python - 在 as 之后用逗号导入

php - 用正则表达式匹配所有三种 PHP 注释

php - 在 TYPO3 Fluid 中显示按年和按月分组的元素列表

php - require_once 忽略

php/Wordpress/Ajax 按钮调用 php 脚本

WordPress、站点管理和测试

html - 页面不会扩展到全高 - 页脚下方显示细黑线

c++ - 如何导入将 [c++] 类导入 [objective-c] 类的 [objective-c++] 类?

Java导入包

image - 为图像添加自动超链接