Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Work in progress:
- * Adds a new column on the transactions admin page and displays invoice number from primary registrant's answers
- * The question ID is hardcoded in the function bc_transaction_list_table_invoiceColumn()
- * Global variables should probably be removed for production sites
- */
- // the URL for every espresso admin page will contain a URL parameter named "page"
- // set the following variable equal to that URL parameter
- $espresso_admin_page = 'espresso_transactions';
- $custom_column_name = 'invoiceColumn';
- // now add the hooks
- add_filter(
- "FHEE_manage_event-espresso_page_{$espresso_admin_page}_columns",
- "bc_filter_transaction_list_table_columns", 10, 2
- );
- add_action(
- "AHEE__EE_Admin_List_Table__column_{$custom_column_name}__event-espresso_page_{$espresso_admin_page}",
- "bc_transaction_list_table_{$custom_column_name}", 10, 2
- );
- /**
- * this function adds the column name to the array of table headers
- * @return array
- */
- function bc_filter_transaction_list_table_columns( $columns, $screen ) {
- global $espresso_admin_page;
- global $custom_column_name;
- if ( $screen === "{$espresso_admin_page}_default" ) {
- $columns = EEH_Array::insert_into_array(
- $columns,
- array( $custom_column_name => 'Invoice' ),
- 'TXN_ID',
- false
- );
- }
- return $columns;
- }
- /**
- * this function echoes out the data you want to appear in your custom column.
- * change "myCustomColumnName" in the function name to match the value of $custom_column_name
- *
- * @param \EE_transaction $item
- * @param string $screen
- */
- function bc_transaction_list_table_invoiceColumn( $transaction, $screen ) {
- global $espresso_admin_page;
- // echo "Its class is " , get_class($transaction) , "\n";
- if ( $screen === "{$espresso_admin_page}_default" && $transaction instanceof EE_Transaction ) {
- // echo 'txn_id: '.$transaction->ID().' ';
- $reg = $transaction->get_first_related( 'Registration' );
- if ( $reg instanceof EE_Registration ) {
- $att = $reg->attendee();
- if( $att instanceof EE_Attendee ) {
- $answer_value = EEM_Answer::instance()->get_var(
- array(
- array(
- 'Registration.ATT_ID' => $att->ID(),
- 'Registration.TXN_ID' => $transaction->ID(),
- 'QST_ID' => 21 // Custom Question ID for Invoice Number
- ),
- 'order_by' => array(
- 'ANS_ID' => 'DESC'
- ),
- 'limit' => 1
- ),
- 'ANS_value'
- );
- echo ! empty( $answer_value ) ? $answer_value : 'invoice not found';
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement