Created
March 1, 2024 17:14
-
-
Save rickalday/a4b37a8a7f12322de9bded617f561723 to your computer and use it in GitHub Desktop.
Add a checkbox to export the donation Transaction ID in GiveWP donation history export
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 give_export_transaction_id() { | |
?> | |
<tr class="give-export-option-fields give-export-option-custom-field"> | |
<td scope="row" class="row-title"> | |
<label><?php esc_html_e( 'Transaction ID:', '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[transaction_id]" | |
id="give-export-transaction_id"><?php _e( 'Transaction ID', 'give' ); ?> | |
</label> | |
</li> | |
</ul> | |
</div> | |
</td> | |
</tr> | |
<?php | |
} | |
add_action( 'give_export_donation_fields', 'give_export_transaction_id' ); | |
/** | |
* 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_transaction_id_column_header( $cols ) { | |
if ( isset( $cols['transaction_id'] ) ) { | |
$cols['transaction_id'] = __( 'Transaction ID', 'give' ); | |
} | |
return $cols; | |
} | |
add_filter( 'give_export_donation_get_columns_name', 'give_export_transaction_id_column_header' ); | |
/** | |
* This function populates the CSV with the custom field data. Add an if statement for each aditional field. | |
*/ | |
function give_export_transaction_id_data( $data, $payment, $columns ) { | |
if ( ! empty( $columns['transaction_id'] ) ) { | |
$transactionID = $payment->get_meta( '_give_payment_transaction_id' ); | |
$data['transaction_id'] = isset( $transactionID ) ? wp_kses_post( $transactionID ) : ''; | |
} | |
return $data; | |
} | |
add_filter( 'give_export_donation_data', 'give_export_transaction_id_data', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment