Created
April 8, 2020 20:39
-
-
Save rickalday/d559790584f76f5d9583a4e57dbb7790 to your computer and use it in GitHub Desktop.
Add Anonymous Donation field in GiveWP form CSV
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
/** | |
* Add Anonymous Donation Data fields in export donor fields tab. | |
*/ | |
function give_anonymous_donation_standard_donor_fields() { | |
?> | |
<li> | |
<label for="give-anonymous-donations"> | |
<input type="checkbox" checked | |
name="give_give_donations_export_option[give_anonymous_donation]" | |
id="give_anonymous_donation"><?php _e( 'Anonymous Donation', 'give' ); ?> | |
</label> | |
</li> | |
<?php | |
} | |
add_action( 'give_export_donation_standard_donor_fields', 'give_anonymous_donation_standard_donor_fields' ); | |
/** | |
* Add Anonymous Donation header in CSV. | |
*/ | |
function give_anonymous_donation_update_columns_heading( $cols ) { | |
if ( isset( $cols['give_anonymous_donation'] ) ) { | |
$cols['give_anonymous_donation'] = __( 'Anonymous Donation', 'give' ); | |
} | |
return $cols; | |
} | |
add_filter( 'give_export_donation_get_columns_name', 'give_anonymous_donation_update_columns_heading' ); | |
/** | |
* Add Anonymous Donatio fields in CSV. | |
*/ | |
function give_anonymous_donation_export_donation_data( $data, $payment, $columns ) { | |
if ( ! empty( $columns['give_anonymous_donation'] ) ) { | |
$message = $payment->get_meta( '_give_anonymous_donation' ); | |
if ( $message == 1 ){ | |
$data['give_anonymous_donation'] = 'Yes'; | |
} else { | |
$data['give_anonymous_donation'] = 'No'; | |
} | |
} | |
return $data; | |
} | |
add_filter( 'give_export_donation_data', 'give_anonymous_donation_export_donation_data', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment