Skip to main content

/**
* FooEvents – display all orders and Attendees details
*/
add_action(“admin_init”, “ct_display_report5″);
function ct_display_report5()
{
if (!current_user_can(‘administrator’)) {
return false;
}
if (!isset($_GET[‘ct_display_report5’])) {
return false;
}
ct_get_events_data();
}
function ct_get_events_data($flat_data = false)
{
$html = ”;
$html .= ‘

‘;

$orders_from_date = isset($_GET[‘orders_from’]) ? $_GET[‘orders_from’] : ”;
$html .= ‘

‘;
$html .= ‘

‘;
$download_csv_url = ‘/wp-admin/?ct_custom_download_123=yes’;
if ($orders_from_date) {
$download_csv_url = ‘/wp-admin/?ct_custom_download_123=yes&orders_from=’ . $orders_from_date;
$title = ‘Orders from: ‘ . $orders_from_date;
$download_csv_text = ‘? Export orders’;
$more_text = ‘To generate CSV file with orders from ‘ . $orders_from_date . ‘ click here:’;
} else {
$title = ‘Orders all-time’;
$download_csv_text = ‘? Export orders’;
$more_text = ‘To generate CSV file with ALL orders click here:’;
}
$html .= ‘

‘ . $title . ‘

‘;
$html .= ‘

‘ . $more_text . ‘
‘ . $download_csv_text . ‘

‘;
$html .= ‘


‘;
$html .= ‘

Filters

‘;
$html .= ‘

‘;
$html .= ‘‘;
$html .= ‘‘;
$html .= ‘‘;
$html .= ‘Reset filters‘;
$html .= ‘

‘;
$html .= ‘

‘;
// compose data
$csv_data = array();
$columnsNames = array();
$args = array(
‘limit’ => -1,
‘orderby’ => ‘date’,
‘order’ => ‘DESC’,
);
if ($orders_from_date) {
$args[‘date_created’] = ‘>’ . (strtotime($orders_from_date));
}
$query = new WC_Order_Query($args);
$orders = $query->get_orders();
$counter = 0;
$attendeeCounter = 0;
foreach ($orders as $order) {
$counter++;
$html .= ‘

‘;
$html .= ”;$html .= ”;
$html .= ”;
$html .= ”;
$html .= ”;
$html .= ‘

‘ . $counter . ‘. ‘;
$html .= ”;
$order_items = $order->get_items();
$html .= ‘

Order details:‘ . ‘
‘;
$data1 = ”;
$html .= ‘Order number: ‘ . $order->get_order_number() . ‘
‘;
$data1 .= $order->get_date_created() . ‘
‘;
foreach ($order_items as $item_id => $item) {
$product_name = $item[‘name’];
$item_quantity = $order->get_item_meta($item_id, ‘_qty’, true);
$data1 .= $item_quantity . ‘ x ‘ . $product_name . ‘
‘;
}
$data1 .= $order->get_total() . ‘
‘;
$html .= $data1;
$html .= ‘

‘;
$data2 = ”;
$html .= ‘

Billing:‘ . ‘
‘;
$data2 .= $order->get_formatted_billing_address();
$data2 .= $order->get_billing_email() . ‘
‘;
$data2 .= $order->get_billing_phone() . ‘
‘;
$html .= $data2;
$html .= ‘

‘;
$html .= ‘

‘;
$html .= ‘Additional Fields:‘ . ‘
‘;
$data3 = ”;
$data3 .= ‘Title: ‘ . $order->get_meta(‘additional_contact_title’) . ‘
‘;
$data3 .= ‘First Name: ‘ . $order->get_meta(‘additional_contact_first_name’) . ‘
‘;
$data3 .= ‘Last Name: ‘ . $order->get_meta(‘additional_contact_last_name’) . ‘
‘;
$data3 .= ‘Registration E-mail: ‘ . $order->get_meta(‘additional_contact_email’) . ‘
‘;
$data3 .= ‘E-mail who will receive on-site alerts: ‘ . $order->get_meta(‘additional_contact_alert’) . ‘
‘;
$data3 .= ‘Job Title: ‘ . $order->get_meta(‘additional_contact_position’) . ‘
‘;
$data3 .= ‘Phone: ‘ . $order->get_meta(‘additional_contact_phone’) . ‘
‘;
$html .= $data3;
$html .= ‘

‘;
$html .= ‘

‘;
$details = $order->get_meta(‘WooCommerceEventsOrderTickets’);
$html .= ‘Attendees:

‘;
$data4 = ”;
foreach ($details as $customAttendee) {
foreach ($customAttendee as $key1 => $ticket) {
$attendeeCounter++;
$data4 .= ‘‘ . get_the_title($ticket[‘WooCommerceEventsProductID’]) . ‘
‘;
$data4 .= ‘Attendee ‘ . ($key1) . ‘‘ . ‘
‘;
$data4 .= ‘WooCommerceEventsPurchaserFirstName: ‘ . $ticket[‘WooCommerceEventsPurchaserFirstName’] . ‘
‘;
$data4 .= ‘WooCommerceEventsPurchaserLastName: ‘ . $ticket[‘WooCommerceEventsPurchaserLastName’] . ‘
‘;
$data4 .= ‘WooCommerceEventsPurchaserEmail: ‘ . $ticket[‘WoCommerceEventsPurchaserEmail’] . ‘
‘;
// collect attendee data for CSV lines
$columnsNames[‘WooCommerceEventsProductID’] = ‘—‘;
$columnsNames[‘AttendeeCounter’] = ‘—‘;
$csv_data[$attendeeCounter][‘WooCommerceEventsProductID’] .= get_the_title($ticket[‘WooCommerceEventsProductID’]);
$csv_data[$attendeeCounter][‘AttendeeCounter’] .= ‘Attendee ‘ . ($key1);
$csv_data[$attendeeCounter][‘WooCommerceEventsPurchaserFirstName’] = $ticket[‘WooCommerceEventsPurchaserFirstName’];
$csv_data[$attendeeCounter][‘WooCommerceEventsPurchaserLastName’] = $ticket[‘WooCommerceEventsPurchaserLastName’];
$csv_data[$attendeeCounter][‘WooCommerceEventsPurchaserEmail’] = $ticket[‘WoCommerceEventsPurchaserEmail’];
$columnsNames[‘WooCommerceEventsPurchaserFirstName’] = ‘—‘;
$columnsNames[‘WooCommerceEventsPurchaserLastName’] = ‘—‘;
$columnsNames[‘WooCommerceEventsPurchaserEmail’] = ‘—‘;
foreach ($ticket[‘WooCommerceEventsCustomAttendeeFields’] as $key => $val) {
$data4 .= $key . ‘: ‘ . $val . ‘
‘;
$csv_data[$attendeeCounter][$key] = $val;
$columnsNames[$key] = ‘—‘;
}
$data4 .= ‘
‘;
}
}
$html .= $data4;
$html .= ‘

‘;
$html .= ‘

‘;
}
$html .= ‘

‘;
$html .= ‘


‘;
if ($flat_data) {
return array($csv_data, $columnsNames);
}
echo $html;
die(“end”);
}