Hi, could you tell me which exporter plugin you are using.? so that I can examine and if possible I will give the patch update for that plugin so that it includes Order Item Meta as well.
Thread Starter
fitbox
(@fitmealat)
Hi Kumar,
thx for the reply.
I am using this one.
i put a snipped in my functions.php to export various extra custom fields that i need.
I also want to include some data from some fields from your plugin.
example for some other data:
//add the data headers
function wc_csv_export_modify_column_headers( $column_headers ) {
$new_headers = array(
'_billing_sundaytime' => 'Montag',
// add other column headers here in the format column_key => Column Name
);
return array_merge($new_headers, $column_headers);
}
add_filter( 'wc_customer_order_csv_export_order_headers', 'wc_csv_export_modify_column_headers' );
//now fill the data”
function wc_csv_export_modify_row_data( $order_data, $order, $csv_generator ) {
$custom_data = array(
'_billing_sundaytime' => get_post_meta( $order->id, '_billing_sundaytime', true ),
);
add_filter( 'wc_customer_order_csv_export_order_row', 'wc_csv_export_modify_row_data', 10, 3 );
for sku for example its alittle more complicated:
global $wpo_wcpdf;
global $wpo_wcpdf_pro;
$rechnungsnummer = $wpo_wcpdf->export->get_invoice_number( $order->id );
//$gutschriftnummer = $wpo_wcpdf_pro->get_number('credit_note', $order->id);
$refunds = $order->get_refunds();
foreach ($refunds as $key => $refund) {
if ($credit_note_number = $wpo_wcpdf_pro->get_number('credit-note', $refund->id)) {
$credit_note_numbers[] = $credit_note_number;
}
}
if ( isset($credit_note_numbers) ) {
$gutschriftnummer = implode(', ', $credit_note_numbers);
}
global $woocommerce, $product;
$bestellte_produkte ="";
//$zutaten_meta = "";
$order = new WC_Order( $order->id );
$items = $order->get_items();
foreach ($items as $item ) {
if ( !empty($item['variation_id']) ) { // Check for a product variation
$id = $item['variation_id']; // Assign variation ID
} else {
$id = $item['product_id']; // Else use base ID
}
$product = new WC_Product($id);
//$zutaten_meta = wc_get_order_item_meta($item_id, $key, $single);
//$sku = $productmeta->post->sku;
$sku = $product->get_sku();
$product_name = $item['name'];
$product_qty = $item['qty'];
//echo $id;
if ( $product_qty > '1') {
$bestellte_produkte .= $product_qty;
$bestellte_produkte .= "x ";
}
$bestellte_produkte .= $sku;
//echo $product_name;
//echo $product_qty;
}
Hi, you are almost there. you could use wc_get_order_item_meta() function to get any order items’s meta. Do some thing like this
Feel free to modify as you need.
function wc_csv_export_modify_column_headers( $column_headers ) {
$new_headers = array(
'order_item_meta' => 'Order Item Meta'
);
return array_merge( $column_headers, $new_headers );
}
add_filter( 'wc_customer_order_csv_export_order_headers', 'wc_csv_export_modify_column_headers' );
// set the data for each for custom columns
function wc_csv_export_modify_row_data( $order_data, $order ) {
$item_metas = array();
$order = new WC_Order( $order->id );
$items = $order->get_items();
foreach ( $items as $item ) {
$item_metas[] = wc_get_order_item_meta( $item_id, "your_wccpf_fields_name" );
}
$custom_data = array(
'order_item_meta' => get_post_meta( $order->id, 'Item Meta', implode( "; ", $item_metas ) )
);
return array_merge( $order_data, $custom_data );
}
add_filter( 'wc_customer_order_csv_export_order_row', 'wc_csv_export_modify_row_data', 10, 2 );
Thread Starter
fitbox
(@fitmealat)
hm its not working all i see in the excel is “array”
i think its because $item_id is not right. Where is it coming from?
$item_metas[] = wc_get_order_item_meta( $item_id, "your_wccpf_fields_name" );
here is what worked after trial and error:
foreach ($items as $item ) {
$item_metas = "";
$order = new WC_Order( $order->id );
$items = $order->get_items();
$item_metas .= implode(" -", $item['item_meta']['your_wccpf_fields_LABEL']);
}...
BUT you have to use the FIELD LABEL!
thanks for the help anyways. maybe i did something wrong 🙂