Support

Home Forums Event Espresso Premium Sorting by custom column in Event's registration table Reply To: Sorting by custom column in Event's registration table

Reply To: Sorting by custom column in Event's registration table

Author Replies
bhesketh # Posted on May 8, 2018 at 7:32 am

I renamed lottery_number to REG_code, because it was actually edited REG_code and it still saves in the database as REG_code.

The lottery_number field is REG_code field that I modified.

1. Here is how I changed the REG_code to make it random within a specific event

function change_reg_code($new_reg_code, $transaction, $ticket) {

global $wpdb;

if ( $ticket instanceof EE_Ticket ) {
$dtt = $ticket->last_datetime();
if ( $dtt instanceof EE_Datetime ) {
$event = $dtt->event();
if ( $event instanceof EE_Event ) {
$evt_id = $event->ID();
}
}
}
$sql = “SELECT REG_code “;
$sql .= “FROM {$wpdb->prefix}esp_registration “;
$sql .= “WHERE {$wpdb->prefix}esp_registration.EVT_ID = %d”;

$attendees = $wpdb->get_results( $wpdb->prepare( $sql, $evt_id ));

$new_reg_code = strval(rand(100, 999));
while(array_filter($attendees, function ($e) use ($new_reg_code) {return $e->REG_code == $new_reg_code;}))
{
$new_reg_code = strval(rand(100, 999));
}

return $new_reg_code;
}
add_filter(‘FHEE__Create__regCode__new_reg_code’,’change_reg_code’, 10, 3);

2. Then I added this new REG_code which is my random lottery number to registrations table

add_filter( “FHEE_manage_event-espresso_page_espresso_registrations_columns”,”bc_filter_registration_list_table_columns”, 10, 2);

function bc_filter_registration_list_table_columns( $columns, $screen ) {

if ( $screen === “espresso_registrations_default” ) {
$columns[‘REG_code’] = ‘Lottery #’;
other columns come here …

}
return $columns;
}

add_action( “AHEE__EE_Admin_List_Table__column_REG_code__event-espresso_page_espresso_registrations”,”bc_registration_list_table_lottery_number”, 10, 2);

// Add lottery number
function bc_registration_list_table_lottery_number( $item, $screen ) {

if ( $screen === “espresso_registrations_default” && $item instanceof EE_Registration ) {

$reg_code = $item->reg_code();
echo $reg_code;
}
}

3. Add sorting by the lottery number (REG_code) column

function tw_ee_sortable_columns( $sortable_columns, $screen ) {

if ( $screen == ‘espresso_registrations_default’ ) {
$sortable_columns[‘REG_code’] = array(‘REG_code’ => TRUE);
}
return $sortable_columns;
}
add_filter(‘FHEE_manage_event-espresso_page_espresso_registrations_sortable_columns’, ‘tw_ee_sortable_columns’, 10, 2);

Issue – when I click on Lottery number column heading I get sorting by date instead.

Do NOT follow this link or you will be banned from the site!