Created
March 15, 2025 01:47
-
-
Save rickalday/f83c2323c51f598a0573efa4008a9b0e to your computer and use it in GitHub Desktop.
Export Gift Aid data in Donation History Export Tool
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function give_export_gift_aid() { | |
?> | |
<li> | |
<label for="give-export-payment-gift_aid"> | |
<input type="checkbox" checked name="give_give_donations_export_option[gift_aid]" id="give-export-gift_aid"><?php _e( 'Gift Aid', 'give' ); ?> | |
</label> | |
</li> | |
<?php | |
} | |
add_action( 'give_export_donation_standard_payment_fields', 'give_export_gift_aid' ); | |
/** | |
* 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_gift_aid_column_header( $cols ) { | |
if ( isset( $cols['gift_aid'] ) ) { | |
$cols['gift_aid'] = __( 'Gift Aid', 'give' ); | |
} | |
return $cols; | |
} | |
add_filter( 'give_export_donation_get_columns_name', 'give_export_gift_aid_column_header' ); | |
/** | |
* This function populates the CSV with the custom field data. Add an if statement for each aditional field. | |
*/ | |
use Give\Subscriptions\Models\Subscription; | |
function give_export_gift_aid_data( $data, $payment, $columns, $instance ) { | |
if ( ! empty( $columns['gift_aid'] ) ) { | |
// Renewals will have the subscription_id metakey | |
$is_renewal = $payment->get_meta( 'subscription_id' ); | |
//error_log( 'Renewal: '. $is_renewal ); | |
//If it's a renewal, get the Gift Aid data from the parent payment | |
if ( ! empty( $columns['gift_aid'] )) { | |
if ( ! empty( $is_renewal ) ) { | |
// Get the parent donation. | |
$parent_donation_id = wp_get_post_parent_id( $payment->ID ); | |
if ( metadata_exists( 'post', $parent_donation_id, '_give_gift_aid_accept_term_condition' ) ) { | |
$data['gift_aid'] = 'on'; | |
} | |
} else { | |
//$gift_data = | |
$data['gift_aid'] = $payment->get_meta( '_give_gift_aid_accept_term_condition' ); | |
} | |
} | |
} | |
return $data; | |
} | |
add_filter( 'give_export_donation_data', 'give_export_gift_aid_data', 90, 4 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment