단비 배송조회 – Order/Customer CSV Export 플러그인 연동

| 2015년 9월 30일

Order/Customer CSV Export 플러그인으로 주문 내역을 CSV 파일로 내보내기할 때 배송 택배회사와 송장번호를 추가하는 방법입니다. 테마의 functions.php에 다음과 같이 추가하십시오.
[php]
// add custom column headers
function wc_csv_export_modify_column_headers( $column_headers ) {

$new_headers = array(
‘shipping_provider’ => ‘택배사’,
‘shipping_invoice’ => ‘운송장 번호’,
// add other column headers here in the format column_key => Column Name
);

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, $csv_generator ) {

$provider = get_post_meta($order->id, ‘_shipping_provider’, true);
if (!empty($provider)) {
$provider = DanbiShipping::$SHIPPING_PROVIDER[$provider][‘title’];
$invoice = get_post_meta($order->id, ‘_shipping_invoice’, true);
} else {
$invoice = ”;
}

$custom_data = array(
‘shipping_provider’ => $provider,
‘shipping_invoice’ => $invoice
// add other row data here in the format column_key => data
);

$new_order_data = array();

if ( isset( $csv_generator->order_format ) &&
( ‘default_one_row_per_item’ == $csv_generator->order_format ||
‘legacy_one_row_per_item’ == $csv_generator->order_format ) ) {
foreach ( $order_data as $data ) {
$new_order_data[] = array_merge( (array) $data, $custom_data );
}
} else {
$new_order_data = array_merge( $order_data, $custom_data );
}

return $new_order_data;
}
add_filter( ‘wc_customer_order_csv_export_order_row’, ‘wc_csv_export_modify_row_data’, 10, 3 );
[/php]

※ 참고
Customizing Order CSV Output