Created
September 3, 2025 15:44
-
-
Save rickalday/37c8fceaab75eb4cee35a74e36d05f69 to your computer and use it in GitHub Desktop.
Add a checkbox to export the donation base amount in GiveWP donation history export
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_give_cs_base_amount() { | |
| ?> | |
| <tr class="give-export-option-fields give-export-option-custom-field"> | |
| <td scope="row" class="row-title"> | |
| <label><?php esc_html_e( 'Base amount:', '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[give_cs_base_amount]" | |
| id="give-export-give_cs_base_amount"><?php _e( 'Base amount', 'give' ); ?> | |
| </label> | |
| </li> | |
| </ul> | |
| </div> | |
| </td> | |
| </tr> | |
| <?php | |
| } | |
| add_action( 'give_export_donation_fields', 'give_export_give_cs_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_column_headers( $cols ) { | |
| if ( isset( $cols['give_cs_base_amount'] ) ) { | |
| $cols['give_cs_base_amount'] = __( 'Base amount', 'give' ); | |
| } | |
| return $cols; | |
| } | |
| add_filter( 'give_export_donation_get_columns_name', 'give_export_column_headers' ); | |
| /** | |
| * This function populates the CSV with the custom field data. Add an if statement for each aditional field. | |
| */ | |
| function give_export_cs_data( $data, $payment, $columns ) { | |
| if ( ! empty( $columns['give_cs_base_amount'] ) ) { | |
| $baseAmount = $payment->get_meta( '_give_cs_base_amount' ); | |
| $data['give_cs_base_amount'] = isset( $baseAmount ) ? wp_kses_post( $baseAmount ) : ''; | |
| } | |
| return $data; | |
| } | |
| add_filter( 'give_export_donation_data', 'give_export_cs_data', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment