Last active
August 1, 2025 17:29
-
-
Save rickalday/f83c2323c51f598a0573efa4008a9b0e to your computer and use it in GitHub Desktop.
Export Gift Aid data in Donation History Export Tool
This file contains hidden or 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. | |
| */ | |
| function give_export_gift_aid_data( $data, $payment, $columns, $instance ) { | |
| if ( ! empty( $columns['gift_aid'] ) ) { | |
| // Get the post object | |
| $post = get_post( $payment->ID ); | |
| // Check if the post has a parent | |
| if ($post && $post->post_parent) { | |
| // Get the parent post ID | |
| $parent_id = $post->post_parent; | |
| // Get the meta value from the parent post | |
| $meta_value = get_post_meta($parent_id, '_give_gift_aid_accept_term_condition', true); | |
| // Check if the meta value exists and equals 'on' | |
| if ($meta_value === 'on') { | |
| $data['gift_aid'] = 'on'; | |
| } else { | |
| $data['gift_aid'] = ''; | |
| } | |
| } else { | |
| $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