Skip to content

Instantly share code, notes, and snippets.

@rickalday
Created July 6, 2023 19:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rickalday/d15838fb57749a9c4c525167fb24c97d to your computer and use it in GitHub Desktop.
Save rickalday/d15838fb57749a9c4c525167fb24c97d to your computer and use it in GitHub Desktop.
Export custom fields without a value
function export_option_givewp_field_api_fields() {
?>
<tr class="give-export-option-fields give-export-option-custom-field">
<td scope="row" class="row-title">
<label><?php esc_html_e( 'Custom Field Title:', '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( 'Accept Mailing List', 'give' ); ?>
</label>
</li>
</ul>
</div>
</td>
</tr>
<?php
}
add_action( 'give_export_donation_fields', 'export_option_givewp_field_api_fields' );
/**
* Thi 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_field_api_fields( $cols ) {
if ( isset( $cols['accept-mailing-list'] ) ) {
$cols['accept-mailing-list'] = __( 'Accept Mailing List', 'give' );
}
return $cols;
}
add_filter( 'give_export_donation_get_columns_name', 'column_header_givewp_field_api_fields' );
/**
* This function populates the CSV with the custom field data. Add an if statement for each aditional field.
*/
function export_givewp_field_api_fields( $data, $payment, $columns ) {
if ( ! empty( $columns['accept-mailing-list'] ) ) {
if ( metadata_exists( 'post', $payment->ID, 'accept_t_and_c' ) ) {
$data['accept-mailing-list'] = 'Accepted';
}
}
return $data;
}
add_filter( 'give_export_donation_data', 'export_givewp_field_api_fields', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment