Last active
October 17, 2023 16:19
-
-
Save rickalday/41aeeb4705922690f7e0de2e8dafc1bd to your computer and use it in GitHub Desktop.
Export Mailchimp status in GiveWP
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 export_option_givewp_mc_fields() { | |
?> | |
<tr class="give-export-option-fields give-export-option-custom-field"> | |
<td scope="row" class="row-title"> | |
<label><?php esc_html_e( 'MailChimp:', 'give' ); ?></label> | |
</td> | |
<td class="give-field-wrap"> | |
<div class="give-clearfix"> | |
<ul class="give-export-option-custom-fields-ul"> | |
<!-- Custom field checkbox --> | |
<li class="give-export-option-start"> | |
<label for="give-custom-field"> | |
<input type="checkbox" checked | |
name="give_give_donations_export_option[accept-mailing-list]" | |
id="accept-mailing-list"><?php _e( 'MailChimp', 'give' ); ?> | |
</label> | |
</li> | |
</ul> | |
</div> | |
</td> | |
</tr> | |
<?php | |
} | |
add_action( 'give_export_donation_fields', 'export_option_givewp_mc_fields' ); | |
/** | |
* This function sets the column header in the generated CSV file for the custom field. Add an if statement for each aditional field. | |
*/ | |
function column_header_givewp_mc_field( $cols ) { | |
if ( isset( $cols['accept-mailing-list'] ) ) { | |
$cols['accept-mailing-list'] = __( 'MailChimp', 'give' ); | |
} | |
return $cols; | |
} | |
add_filter( 'give_export_donation_get_columns_name', 'column_header_givewp_mc_field' ); | |
/** | |
* This function populates the CSV with the custom field data. Add an if statement for each aditional field. | |
*/ | |
function export_givewp_mc_field( $data, $payment, $columns ) { | |
if ( ! empty( $columns['accept-mailing-list'] ) ) { | |
$data['accept-mailing-list'] = ''; | |
if ( metadata_exists( 'post', $payment->ID, '_give_mc_donation_optin_status' ) ) { | |
$data['accept-mailing-list'] = 'Opted-in'; | |
} | |
} | |
return $data; | |
} | |
add_filter( 'give_export_donation_data', 'export_givewp_mc_field', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment