Skip to content

Instantly share code, notes, and snippets.

@rickalday
Created February 12, 2025 00:11
Show Gist options
  • Save rickalday/6c42e159b64867257014ab9fcf1ff60d to your computer and use it in GitHub Desktop.
Save rickalday/6c42e159b64867257014ab9fcf1ff60d to your computer and use it in GitHub Desktop.
Adds a new checkbox in the Donation History Export that includes the subscription profile ID
<?php
function give_export_profile_id() {
?>
<li>
<label for="give-export-payment-subscription_profile_id">
<input type="checkbox" checked name="give_give_donations_export_option[subscription_profile_id]" id="give-export-subscription_profile_id"><?php _e( 'Subscripton Profile ID', 'give' ); ?>
</label>
</li>
<?php
}
add_action( 'give_export_donation_standard_payment_fields', 'give_export_profile_id' );
/**
* Thi function sets the column header in the generated CSV file for the custom field. Add an if statement for each aditional field.
*/
function give_export_profile_id_column_header( $cols ) {
if ( isset( $cols['subscription_profile_id'] ) ) {
$cols['subscription_profile_id'] = __( 'Subscripton Profile ID', 'give' );
}
return $cols;
}
add_filter( 'give_export_donation_get_columns_name', 'give_export_profile_id_column_header' );
/**
* This function populates the CSV with the custom field data. Add an if statement for each aditional field.
*/
function give_export_subscription_profile_id_data( $data, $payment, $columns ) {
if ( ! empty( $columns['subscription_profile_id'] ) ) {
$subscription = give_recurring_get_subscription_by( 'payment', $payment->ID );
$profile_id = $subscription->profile_id;
$data['subscription_profile_id'] = isset( $profile_id ) ? wp_kses_post( $profile_id ) : '';
}
return $data;
}
add_filter( 'give_export_donation_data', 'give_export_subscription_profile_id_data', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment