Last active
August 29, 2015 14:04
-
-
Save tamarazuk/f79a704928e4bbb90899 to your computer and use it in GitHub Desktop.
woocommerce-customer-order-csv-export-add-line-item-meta.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment