Advertisement
Guest User

Untitled

a guest
Jul 17th, 2018
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.68 KB | None | 0 0
  1.  
  2. /*
  3.  * Work in progress:
  4.  * Adds a new column on the transactions admin page and displays invoice number from primary registrant's answers
  5.  * The question ID is hardcoded in the function bc_transaction_list_table_invoiceColumn()
  6.  * Global variables should probably be removed for production sites
  7.  */
  8.  
  9.  
  10. // the URL for every espresso admin page will contain a URL parameter named "page"
  11. // set the following variable equal to that URL parameter
  12.  
  13. $espresso_admin_page = 'espresso_transactions';
  14. $custom_column_name = 'invoiceColumn';
  15.  
  16. // now add the hooks
  17. add_filter(
  18.   "FHEE_manage_event-espresso_page_{$espresso_admin_page}_columns",
  19.   "bc_filter_transaction_list_table_columns", 10, 2
  20. );
  21. add_action(
  22.   "AHEE__EE_Admin_List_Table__column_{$custom_column_name}__event-espresso_page_{$espresso_admin_page}",
  23.   "bc_transaction_list_table_{$custom_column_name}", 10, 2
  24. );
  25.  
  26. /**
  27.  * this function adds the column name to the array of table headers
  28.  * @return array
  29.  */
  30.  
  31. function bc_filter_transaction_list_table_columns( $columns, $screen ) {
  32.  
  33.   global $espresso_admin_page;
  34.   global $custom_column_name;
  35.  
  36.   if ( $screen === "{$espresso_admin_page}_default" ) {
  37.     $columns = EEH_Array::insert_into_array(
  38.       $columns,
  39.       array( $custom_column_name => 'Invoice' ),
  40.       'TXN_ID',
  41.       false
  42.     );
  43.   }
  44.   return $columns;
  45. }
  46.  
  47. /**
  48.  * this function echoes out the data you want to appear in your custom column.
  49.  * change "myCustomColumnName" in the function name to match the value of $custom_column_name
  50.  *
  51.  * @param \EE_transaction $item
  52.  * @param string           $screen
  53.  */
  54. function bc_transaction_list_table_invoiceColumn( $transaction, $screen ) {
  55.  
  56.   global $espresso_admin_page;
  57.  
  58.   // echo "Its class is " , get_class($transaction) , "\n";
  59.  
  60.   if ( $screen === "{$espresso_admin_page}_default" && $transaction instanceof EE_Transaction ) {
  61.    
  62.     // echo 'txn_id: '.$transaction->ID().' ';
  63.  
  64.     $reg = $transaction->get_first_related( 'Registration' );
  65.  
  66.     if ( $reg instanceof EE_Registration ) {
  67.      
  68.       $att = $reg->attendee();
  69.      
  70.       if( $att instanceof EE_Attendee ) {
  71.         $answer_value = EEM_Answer::instance()->get_var(
  72.           array(
  73.             array(
  74.               'Registration.ATT_ID' => $att->ID(),
  75.               'Registration.TXN_ID' => $transaction->ID(),
  76.               'QST_ID' => 21 // Custom Question ID for Invoice Number
  77.             ),
  78.             'order_by' => array(
  79.               'ANS_ID' => 'DESC'
  80.             ),
  81.             'limit' => 1
  82.           ),
  83.           'ANS_value'
  84.         );
  85.  
  86.         echo ! empty( $answer_value ) ? $answer_value : 'invoice not found';
  87.  
  88.       }            
  89.     }
  90.   }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement