woocommerce-customer-order-csv-export-add-line-item-meta.php
<?php
/**
* Add weight as line item meta in CSV export Default format
*/
function sv_add_weight_to_csv_export_line_item( $line_item, $item, $product, $order ) {
$line_item['weight'] = $product->get_weight();
return $line_item;
}
add_filter( 'wc_customer_order_csv_export_order_line_item', 'sv_add_weight_to_csv_export_line_item', 10, 4 );
/**
* Add weight as line item meta in CSV export CSV Import format
*/
function sv_add_weight_to_csv_export_import_format( $order_data, $order ) {
$count = 1;
// add line items
foreach ( $order->get_items() as $item ) {
$product = $order->get_product_from_item( $item );
if ( ! is_object( $product ) ) {
$product = new WC_Product( 0 );
}
if ( $weight = $product->get_weight() ) {
$order_data[ "order_item_{$count}" ] .= '|weight: ' . $weight;
}
$count++;
}
return $order_data;
}
add_filter( 'wc_customer_order_csv_export_order_row', 'sv_add_weight_to_csv_export_import_format', 20, 2 );