Last active
April 25, 2019 17:01
-
-
Save Pebblo/c38802287e59dcded1260e4303f91ce1 to your computer and use it in GitHub Desktop.
This function adds the last payment method selected on a transaction if there are no payments on the transaction.
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 //Please do not include the opening PHP tag if you already have one | |
add_filter('FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array', 'tw_ee_add_last_payment_method_to_csv', 10, 2); | |
function tw_ee_add_last_payment_method_to_csv($reg_csv_array, $reg_row) { | |
//If this is now a primary registrant row, return and do nothing | |
if($reg_row['Registration.REG_count'] != '1'){ | |
return $reg_csv_array; | |
} | |
//Check if payment method(s) is empty | |
if( empty($reg_csv_array['Payment Method(s)']) ) { | |
//If payment method(s) is empty, pull the transaction object | |
$transaction = EEM_Transaction::instance()->get_one_by_ID($reg_row['Registration.TXN_ID']); | |
//Check we do actually have an EE_Transaction object | |
if($transaction instanceof EE_Transaction){ | |
//Pull the last payment method from the EE_Transaction | |
//if we don't have a payment method at this point, the user didn't finalize | |
//so we set the value to 'Unknown' | |
$payment_method = $transaction->payment_method(); | |
$reg_csv_array['Payment Method(s)'] = $payment_method instanceof EE_Payment_Method | |
? $payment_method->admin_name() | |
: esc_html__('Unknown', 'event_espresso'); | |
} | |
} | |
return $reg_csv_array; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment