Is it possible to add additional columns (to sort through the transactions) on the Transactions page?
We created custom questions for the registration page such as Billing Name and Billing Company. Would we be able to have these fields on the Transaction page?
I don’t have an example of doing this currently, but there are filters within Event Espresso that will allow you to do this via code. I have an example of adding a custom column to the registrations list table, which can be found here:
So, for example FHEE_manage_event-espresso_page_espresso_transactions_columns filters the columns on that output.
AHEE__EE_Admin_List_Table__column_{column-name}__event-espresso_page_espresso_registrations filters the content of that specific custom column for you to add details into it.
FHEE_manage_event-espresso_page_espresso_transactions_sortable_columns allows you to set the sortable columns.
function transaction_table_company_or_band_question( $item, $screen ){
//Sanity check to confirm we have an EE_Transaction object.
if($item instanceof EE_Transaction){
//Pull the answer object for Question ID 21 using the current registration.
$question_id = 21;
$answer_obj = EEM_Answer::instance()->get_registration_question_answer_object( $item, $question_id );
if ( $answer_obj instanceof EE_Answer ){
//If we have an answer object, echo the 'pretty' value for it.
echo $answer_obj->pretty_value();
}
}
}
Yeah your within the transaction list table, the example I gave you was for the registration list table.
That means that in my example the $item being passed is a registration object (which is what the questions are linked to), but in the transaction list table, that’s going to be the EE_Transaction object.
You need check what object you have within $item to know where you need to do from there.
Also, by ‘the data isn’t pulling through’ do you have the custom column created within the transaction table? Theres much more code needed than the above for all of this.
What is ‘transaction_table_company_or_band_question’ set to hook into for example?
Thank you for the information, I am going to check out Kint.
Here is the entire code I am working with, same as what you shared but I am slowing going through it making changes and trying to understand how it all works.
This is still a work in progress (I’m not a PHP whiz – learning though!)
//Add columns to Transaction page *Under Construction*
function tw_custom_columns( $columns, $screen ) {
// This is for the 'default' transactions list table
// Event Espresso -> Transactions.
if($screen == 'espresso_transactions_default'){
// EEH_Array::insert_into_array() allows you to specific a specific key
// that you want to add your additional column before/after.
// This adds the custom columns just before 'actions' column.
$columns = EEH_Array::insert_into_array(
$columns,
array( 'company-or-band-name-column' => 'Company or Band Name',
'billing-first-name-column' => 'Billing First Name',
'billing-last-name-column' => 'Billing Last Name'
),
'actions'
);
}
//Add a custom-reg-qst-column column to the transactions list table.
if($screen == 'espresso_transactions_event_transactions') {
//This is another method you can use that just adds the column to the end of the array.
$columns['company-or-band-name-column'] = 'Company or Band Name';
}
return $columns;
}
add_filter('FHEE_manage_event-espresso_page_espresso_transactions_columns', 'tw_custom_columns', 10, 2);
function transaction_table_company_or_band_question( $item, $screen ){
//Sanity check to confirm we have an EE_Transaction object.
if($item instanceof EE_Transaction){
//Pull the answer object for Question ID 21 using the current registration.
$question_id = 21;
$answer_obj = EEM_Answer::instance()->get_registration_question_answer_object( $item, $question_id );
if ( $answer_obj instanceof EE_Answer ){
//If we have an answer object, echo the 'pretty' value for it.
echo $answer_obj->pretty_value();
}
}
}
// 'company-or-band-name-column' in the action name here needs to be changed to match your column name set in the function above.
add_action( 'AHEE__EE_Admin_List_Table__column_company-or-band-name-column__event-espresso_page_espresso_transactions', 'tw_checkin_table_custom_question', 10, 2 );
//Enable sorting for the custom column.
function tw_ee_sortable_columns( $sortable_columns, $screen ) {
if ( $screen == 'espresso_transactions_default' ) {
$sortable_columns['company-or-band-name-column'] = array('company-or-band-name-column' => false);
}
return $sortable_columns;
}
add_filter('FHEE_manage_event-espresso_page_espresso_transactions_sortable_columns', 'tw_ee_sortable_columns', 10, 2);
// The models only accept certain values for orderby, normally the column name is used but if thats custom we'll need to pass a value
// the models understand. THis sets the order by to 'Answer.ANS_value' when you select the custom column above.
function tw_ee_get_orderby_for_transactions_query( $order_by, $request)
{
if( isset($order_by['company-or-band-name-column'] ) ) {
$fixed_order_by = array(
'Answer.ANS_value' => $order_by['company-or-band-name-column']
);
unset($order_by['company-or-band-name-column']);
foreach( $order_by as $key => $value) {
$fixed_order_by[$key] = $value;
}
return $fixed_order_by;
}
//Return the original order_by array.
return $order_by;
}
add_filter('FHEE__Transactions_Admin_Page___get_orderby_for_transactions_query', 'tw_ee_get_orderby_for_transactions_query', 10, 2);
Did you install and activate the “Duck Kint Debugger” plugin I linked above, that looks like you are getting a fatal error because d(); doesn’t exist.
Viewing 10 reply threads
The support post ‘Add Extra Columns to Transactions Page’ is closed to new replies.
Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.
Support forum for Event Espresso 3 and Event Espresso 4.