Reputation: 735
Since WooCommerce 3.x there is native Brand support now. However, Brands are not part of the Default Import/Export functionality of a Product. I found the documentation on how to add a custom column in 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 );
Using $product->get_meta( 'brands', true, 'edit' );
did not work out. How can I add Brands to the import/export?
UPDATE: What I did to fix this problem.. - Moved Brands to "Tags" Column - On Admin, Bulk Edit Products by tag, and mark the corresponding Column.
Upvotes: 2
Views: 2921
Reputation: 1646
Filter you want to hook into will be: 'woocommerce_product_export_product_column_{$column_slug}'.
So if your custom column name is product_brand
, then add_filter
will be like:
add_filter( 'woocommerce_product_export_product_column_product_brand', 'add_export_data', 10, 2 );
function add_export_data( $value, $product ) {
$value = $product->get_meta( 'product_brand', true, 'edit' );
return $value;
}
If your custom column name is brands
, then add_filter
will be like:
add_filter( 'woocommerce_product_export_product_column_brands', 'add_export_data', 10, 2 );
function add_export_data( $value, $product ) {
$value = $product->get_meta( 'brands', true, 'edit' );
return $value;
}
Upvotes: 0
Reputation: 113
I've been using the Ultimate Brands plugin & thought too there must be a way of updating the custom taxonomy values via CSV. I managed to import brand names using the Woocommerce Product CSV Import Suite but have yet to find a way to export via the Woocommerce built in Exporter. Not being a developer, I thought it must be something related to the 'get_terms' function. I've tried many variations with no luck as yet. Was thinking it should look something like this, but not managed to get it to work yet:
function add_export_data() {
$product_id = $post->ID;
$value = get_terms($product_id, 'product_brand');
return $value;
}
Upvotes: 2