Skip to content

Commit 2bf6f42

Browse files
author
Brent Shepherd
authored
Merge pull request #190 from Prospress/issue_138
Exporting custom meta
2 parents 2eedec6 + f0a3d6a commit 2bf6f42

File tree

3 files changed

+45
-3
lines changed

3 files changed

+45
-3
lines changed

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,46 @@ Before exporting, you have the option to modify the column names which are writt
622622
`tax_items` |`string`|Taxes|
623623
`download_permissions` |`int`|Download permissions granted (1 or 0)|
624624

625+
## FAQ
626+
627+
#### Can I export custom meta?
628+
629+
Sure can! You will need to:
630+
631+
1. Use the `wcsie_export_headers` to add your custom header so that it's exported in the CSV and;
632+
2. Use `wcsie_format_export_value` to append the custom export data to each exported row.
633+
634+
```
635+
/**
636+
* Add custom headers to the list of default headers exported in the CSV
637+
*
638+
* @param array $headers
639+
* @return array
640+
*/
641+
function my_custom_export_headers( $headers = array() ) {
642+
return array_merge( $headers, array(
643+
'shipping_code' => 'Shipping Code',
644+
) );
645+
}
646+
add_filter( 'wcsie_export_headers', 'my_custom_export_headers', 10, 1 );
647+
648+
/**
649+
* Adds a custom meta value to the exported row
650+
*
651+
* @param string value
652+
* @param WC_Subscription $subscription
653+
* @param
654+
* @return string
655+
*/
656+
function my_custom_export_values( $value, $subscription, $header_key ) {
657+
if ( 'shipping_code' == $header_key && empty( $value ) ) {
658+
$value = $subscription->shipping_code;
659+
}
660+
661+
return $value;
662+
}
663+
add_filter( 'wcsie_format_export_value', 'my_custom_export_values', 10, 3 );
664+
```
625665

626666
---
627667

includes/class-wcs-export-admin.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public function home_page() {
178178
*/
179179
public function export_headers() {
180180

181-
$csv_headers = array(
181+
$csv_headers = apply_filters( 'wcsie_export_headers', array(
182182
'subscription_id' => __( 'Subscription ID', 'wcs-import-export' ),
183183
'subscription_status' => __( 'Subscription Status', 'wcs-import-export' ),
184184
'customer_id' => __( 'Customer ID', 'wcs-import-export' ),
@@ -231,7 +231,7 @@ public function export_headers() {
231231
'fee_items' => __( 'Fees', 'wcs-import-export' ),
232232
'tax_items' => __( 'Taxes', 'wcs-import-export' ),
233233
'download_permissions' => __( 'Download Permissions Granted', 'wcs-import-export' ),
234-
);
234+
) );
235235
?>
236236

237237
<table class="widefat widefat_importer striped" id="wcsi-headers-table" style="display:none;">

includes/class-wcs-exporter.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,9 +380,11 @@ public static function write_subscriptions_csv_row( $subscription ) {
380380
$value = '';
381381
}
382382

383-
$csv_row[ $header_key ] = $value;
383+
$csv_row[ $header_key ] = apply_filters( 'wcsie_format_export_value', $value, $subscription, $header_key );
384384
}
385385

386+
$csv_row = apply_filters( 'wcsie_format_export_csv_row', $csv_row, $subscription, self::$headers );
387+
386388
self::write( $csv_row );
387389
}
388390

0 commit comments

Comments
 (0)