Last active
April 3, 2025 17:49
-
-
Save rickalday/289e61f5ef3625b000b809ca7608a169 to your computer and use it in GitHub Desktop.
Include Base Amount 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_base_amount() { | |
?> | |
<li> | |
<label for="give-export-payment-base_amount"> | |
<input type="checkbox" checked name="give_give_donations_export_option[base_amount]" id="give-export-base_amount"><?php _e( 'Base Amount', 'give' ); ?> | |
</label> | |
</li> | |
<?php | |
} | |
add_action( 'give_export_donation_standard_payment_fields', 'give_export_base_amount' ); | |
/** | |
* 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_base_amount_column_header( $cols ) { | |
if ( isset( $cols['base_amount'] ) ) { | |
$cols['base_amount'] = __( 'Base Amount', 'give' ); | |
} | |
return $cols; | |
} | |
add_filter( 'give_export_donation_get_columns_name', 'give_export_base_amount_column_header' ); | |
/** | |
* This function populates the CSV with the custom field data. Add an if statement for each aditional field. | |
*/ | |
function give_export_base_amount_data( $data, $payment, $columns, $instance ) { | |
if ( ! empty( $columns['base_amount'] ) ) { | |
// 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_cs_base_amount', true); | |
if ($meta_value) { | |
$data['base_amount'] = $meta_value; | |
} | |
} else { | |
$data['base_amount'] = $payment->get_meta( '_give_cs_base_amount' ); | |
} | |
} | |
return $data; | |
} | |
add_filter( 'give_export_donation_data', 'give_export_base_amount_data', 90, 4 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment