Support

Home Forums Event Espresso Premium Add Extra Columns to Transactions Page

Add Extra Columns to Transactions Page

Posted: August 17, 2023 at 7:20 am

Viewing 10 reply threads


pathwise

August 17, 2023 at 7:20 am

Hello!

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?

Thank you!
https://snipboard.io/VI5r9w.jpg


Tony

  • Support Staff

August 17, 2023 at 3:07 pm

Hi there,

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:

https://gist.github.com/Pebblo/88f2a0a9213c716e4886a249e7709245

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.


pathwise

August 18, 2023 at 10:22 am

Thank you very much for this example.

I am working on it to create 3 extra columns on the Transaction Page; Company or Band Name, Billing First Name, & Billing Last Name.

I am focusing on the first one for now; Company or Band Name.
I have it showing:
https://snipboard.io/MCjw8E.jpg

But the data isn’t pulling through.

Is this the function that pulls through the data?

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();
      } 
    }
}

When I inspect this question on the registration form, it seems it’s ID is 21.
https://snipboard.io/o4VbX0.jpg

Any ideas on what I may be doing wrong?

Thank you very much. ๐Ÿ™‚


Tony

  • Support Staff

August 18, 2023 at 10:25 am

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.

I’d recommend using kint:

https://github.com/DuckDivers/kint-debugger

Add that as a plugin to the site and wrap $item in d();

So d($item); which will output a whole bunch of details for you to dig into ๐Ÿ™‚


Tony

  • Support Staff

August 18, 2023 at 10:29 am

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?


pathwise

August 18, 2023 at 10:41 am

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);


Tony

  • Support Staff

August 18, 2023 at 10:43 am

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 );

Function name needs to be updated to transaction_table_company_or_band_question


pathwise

August 23, 2023 at 8:43 am

Hello Tony,

I tried kint with the debugger plugin but I am not seeing any output: https://snipboard.io/Z3850E.jpg

I know this is outside the scope of EE but do you have any ideas on what is going on here?


Tony

  • Support Staff

August 23, 2023 at 1:17 pm

I’m surprised that doesn’t throw a fatal.

Switch line 259 back to use just:

function transaction_table_company_or_band_question( $item, $screen ) {

Then below that, just before line 261 add:

d($item);

If you not currently getting a fatal from the above code you have in place I’m not so sure it’s running.

Btw you won’t see the output from Kint on that page, its on Event Espresso -> Transactions as that’s where your code is running.


pathwise

August 24, 2023 at 10:39 am

The code is running now and did throw a fatal with what I had before.

Without adding the d($item); I see the following on the Transactions page:https://snipboard.io/UqsRT9.jpg

Once I add d($item);
https://snipboard.io/a8PjwH.jpg

Then the Transactions page is blank:
https://snipboard.io/c6Y0rS.jpg

I appreciate your patience on this one.


Tony

  • Support Staff

August 24, 2023 at 11:55 am

Without adding the d($item); I see the following on the Transactions page:https://snipboard.io/UqsRT9.jpg

Yeah, that because this line:

EEM_Answer::instance()->get_registration_question_answer_object( $item, $question_id );

Expects $item to be an EE_Registration object, but its not, its an EE_Transaction.

Just above $question_id = 21;

Do something like $primary_reg = $transaction->primary_registration();

Then use:

EEM_Answer::instance()->get_registration_question_answer_object( $primary_reg, $question_id );

Once I add d($item);
https://snipboard.io/a8PjwH.jpg

Then the Transactions page is blank:
https://snipboard.io/c6Y0rS.jpg

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.

Event Espresso