Support

Home Forums Event Espresso Premium Customise CSV Report to include ticket URL

Customise CSV Report to include ticket URL

Posted: August 23, 2024 at 4:24 am

Viewing 7 reply threads


keithliew

August 23, 2024 at 4:24 am

Hi, I would like to customise the CSV report so that it can include the ticket URL

However, after my attempt, the CSV file only displayed data for:
1. Last Name
2. First Name
3. Email Address

But not for:
1. Phone Number
2. Ticket URL

Below is the code that I applied:
<?php
/*
Plugin Name: Site plugin for events.heydavid.io
Description: Site specific code for events.heydavid.io
*/
/* Begin Adding Functions Below This Line; Do not include an opening PHP tag as this sample code already includes one! */

/*
* This function allows you to set an array of ‘allowed’ fields that will be output to the registration CSV.
* The order in which they are set in the ‘allowed_fields_in_order’ array is the order that will be used by the CSV itself.
*/
function tw_ee_espresso_reg_report_filter_columns_ordered($csv_row, $registration_db_row)
{
// Set the allowed fields here and also set them in the order you want them to be displayed within the CSV
$allowed_fields_in_order = array(
__(‘Last Name’, ‘event_espresso’),
__(‘First Name’, ‘event_espresso’),
__(‘Email Address’, ‘event_espresso’),
__(‘Phone Number’, ‘event_espresso’),
__(‘Ticket URL’, ‘event_espresso’),
);

// Flip the array so the values are now the keys.
$allowed_fields_in_order = array_flip($allowed_fields_in_order);

// Set the value for each of the array elements to an empty string.
// This is incase any of the above questions do not exist in the current registration’s questions,
// they still need to be included in the row but the value should be nothing.
$allowed_fields_in_order = array_fill_keys(array_keys($allowed_fields_in_order), ”);

// Sets $filtered_csv_row to only contain the ‘allowed’ fields.
$filtered_csv_row = array_intersect_key(
$csv_row,
$allowed_fields_in_order
);

// Now lets set $filtered_csv_row to use the same custom order we set $allowed_fields_in_order to
$filtered_csv_row = array_merge($allowed_fields_in_order, $filtered_csv_row);

return $filtered_csv_row;
}
add_filter(‘FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array’, ‘tw_ee_espresso_reg_report_filter_columns_ordered’, 10, 2);
/* Stop Adding Functions */


Tony

  • Support Staff

August 23, 2024 at 6:02 am

Hi there,

Within that snippet, this array:

$allowed_fields_in_order = array(
__('Last Name', 'event_espresso'),
__('First Name', 'event_espresso'),
__('Email Address', 'event_espresso'),
__('Phone Number', 'event_espresso'),
__('Ticket URL', 'event_espresso'),
);

Sets the names of the CSV fields allow in the order they are used, the names of those fields must match exactly.

So do you have a ‘Phone Number’ field in the CSV or is just ‘Phone’?

If its ‘Phone’ change:

__('Phone Number', 'event_espresso'),

To

__('Phone', 'event_espresso'),

That should fix phone.

—-

Ticket URL isn’t included within the CSV by default, so do you have additional code on the site to add that in?


keithliew

August 23, 2024 at 8:54 am

Hi Tony,

Thank you very much. The ‘Phone’ data is fixed.

No, I don’t have an additional code for the Ticket URL. Can you either:
1. Share any existing Forum posts that have successfully performed this task. OR
2. What code should I add to the PHP file?


Tony

  • Support Staff

August 23, 2024 at 9:28 am

What are you doing with the Ticket URL value?

The reason I ask is the ticket URL uses the REG_url_link from the registration, which you can add to the snippet here:

https://gist.github.com/Pebblo/735d17aa2c4b5939bc1aa0c687815bca

Then just build out the URL passing that value, rather than including the actually URL itself in the CSV.


keithliew

August 23, 2024 at 10:15 am

Hi Tony, I intend to use the Ticket URL in WhatsApp messaging so that the attendees can access the ticket details (with QR code) without digging into their inboxes.

So I just add this code (https://gist.github.com/Pebblo/735d17aa2c4b5939bc1aa0c687815bca) to the existing PHP file for it to work?

Sorry, I’m still not familiar with coding.


Rio

  • Support Staff

August 23, 2024 at 7:37 pm

You can add that code to your Child theme function.php or better, create a plugin so you can easily remove that for testing and if there’s error.

here’s the guide.
https://eventespresso.com/wiki/create-site-specific-plugin-wordpress-site/

thanks


keithliew

August 24, 2024 at 6:18 am

Hi Rio, yes, I created a site-specific plugin and inserted the PHP file into it.

With my limited knowledge I copy and paste the code from https://gist.github.com/Pebblo/735d17aa2c4b5939bc1aa0c687815bca to my PHP file, here is how it looks like:

<?php
/*
Plugin Name: Site plugin for events.heydavid.io
Description: Site specific code for events.heydavid.io
*/
/* Begin Adding Functions Below This Line; Do not include an opening PHP tag as this sample code already includes one! */

/*
* This function allows you to set an array of ‘allowed’ fields that will be output to the registration CSV.
* The order in which they are set in the ‘allowed_fields_in_order’ array is the order that will be used by the CSV itself.
*/
function tw_ee_espresso_reg_report_filter_columns_ordered($csv_row, $registration_db_row)
{
// Set the allowed fields here and also set them in the order you want them to be displayed within the CSV
$allowed_fields_in_order = array(
__(‘Last Name’, ‘event_espresso’),
__(‘First Name’, ‘event_espresso’),
__(‘Email Address’, ‘event_espresso’),
__(‘Phone’, ‘event_espresso’),
__(‘Ticket URL’, ‘event_espresso’),
);

// Flip the array so the values are now the keys.
$allowed_fields_in_order = array_flip($allowed_fields_in_order);

// Set the value for each of the array elements to an empty string.
// This is incase any of the above questions do not exist in the current registration’s questions,
// they still need to be included in the row but the value should be nothing.
$allowed_fields_in_order = array_fill_keys(array_keys($allowed_fields_in_order), ”);

// Sets $filtered_csv_row to only contain the ‘allowed’ fields.
$filtered_csv_row = array_intersect_key(
$csv_row,
$allowed_fields_in_order
);

// Now lets set $filtered_csv_row to use the same custom order we set $allowed_fields_in_order to
$filtered_csv_row = array_merge($allowed_fields_in_order, $filtered_csv_row);

return $filtered_csv_row;
}
add_filter(‘FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array’, ‘tw_ee_espresso_reg_report_filter_columns_ordered’, 10, 2);

function ee_tw_add_reg_url_link_to_csv( $reg_csv_array, $reg_row ) {

$reg_csv_array[ ‘Registraion URL link[REG_url_link]’ ] = $reg_row[ ‘Registration.REG_url_link’ ];
return $reg_csv_array;

}
add_filter( ‘FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array’, ‘ee_tw_add_reg_url_link_to_csv’, 10, 2 );
/* Stop Adding Functions */

The website is crashed.(Note: Before adding the snippet, it was working fine except the Ticket URL filed is still empty)


Rio

  • Support Staff

August 25, 2024 at 6:50 pm

You can troubleshoot that by following this article.
https://eventespresso.com/wiki/troubleshooting-checklist/

Add this block to your wp-config


// Enable WP_DEBUG mode
define( 'WP_DEBUG', true );
if ( WP_DEBUG ) {
        @ini_set( 'display_errors', 0 );
        define( 'WP_DEBUG_LOG', true );
        define( 'WP_DEBUG_DISPLAY', false );
}

then try to enable the plugin again. Once it crash/error, it will send report of error to your domain.com/wp-content/error.log

then send us the log data.

thanks


Rio

  • Support Staff

August 26, 2024 at 12:30 am

You mention the error


August 26, 2024 – [proxy_fcgi:error [pid 26401:tid 140403839801088 [client 2001:f40:935:2ab9:8ddb:3aae:a4e3:5039:0 AH01071: Got error 'PHP message: PHP Parse error: syntax error, unexpected identifier "Name\xe2\x80\x99", expecting ")" in /home/1077368.cloudwaysapps.com/szgngnjyyq/public_html/wp-content/plugins/eventsheydavid/eventsheydavid-customizations.php on line 16', referer: https://events.heydavid.io/homepage/

If it is syntax error, it is commonly on comma, quotation or special characters. This error seems to be in Single quote ‘ because of some site, it is converted to weird styling and instead of just this quote ‘

https://monosnap.com/file/w3DPSyQ3ZEo4Arx6Oma7eclDHsICeV

what you need to do is to replace ‘ with ‘ you can use the search and replace function of notepad++ or any GUI of php.

thanks.


keithliew

August 26, 2024 at 5:26 am

Thank you, it works!


Rio

  • Support Staff

August 26, 2024 at 6:58 am

Awesome. If you need anything, feel free to let us know.

thanks

Viewing 7 reply threads

The support post ‘Customise CSV Report to include ticket URL’ 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