Skip to content

Instantly share code, notes, and snippets.

@mehul0810
Created May 13, 2021 10:29
Show Gist options
  • Save mehul0810/5f06f666180d4da58d2440460c1567f6 to your computer and use it in GitHub Desktop.
Save mehul0810/5f06f666180d4da58d2440460c1567f6 to your computer and use it in GitHub Desktop.
For GiveWP users, you can easliy add custom field and its data to the donation history CSV export.
<?php
/**
* Add data to CSV column.
*
* @param array $columns List of CSV columns.
*
* @since 1.0.0
*
* @return array
*/
function custom_prefix_add_data_to_csv_column( $cols, $columns ) {
$cols['phone'] = esc_html__( 'Phone', 'text-domain' );
return $cols;
}
add_filter( 'give_export_donation_get_columns_name', 'custom_prefix_add_data_to_csv_column', 10, 2 );
/**
* Add data to export CSV.
*
* @param array $data List of prepared CSV data.
* @param Give_Payment $donation Donation Object.
*
* @since 1.0.0
*
* @return void
*/
function custom_prefix_add_data_to_export_csv( $data, $donation ) {
if ( 'ipay88' === $donation->gateway ) { // Select the gateway slug for which you want to add the field.
// Use the custom field meta name instead of `_mg_give_ipay88_phone` to fetch the correct value.
$data['phone'] = ! empty( $donation->payment_meta['_mg_give_ipay88_phone'] ) ? $donation->payment_meta['_mg_give_ipay88_phone'] : '';
}
return $data;
}
add_filter( 'give_export_donation_data', 'custom_prefix_add_data_to_export_csv', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment