Support

Home Forums Event Espresso Premium Plugin to Change Reg-Code

Plugin to Change Reg-Code

Posted: February 1, 2020 at 4:09 am

Viewing 1 reply thread


islamischerweg

February 1, 2020 at 4:09 am

As I got from this (https://eventespresso.com/topic/custom-registration-code-2/) post, the Reg Code is made of 3 components, including transaction id and ticket id.
To change the Reg Code one can use the filter FHEE__EE_Registration_Processor___generate_reg_code__new_reg_code .
In that post a plugin is also linked, which I am using (see at the bottom of this question).

So I’d expect that by using this filter in a custom plugin the Reg Code (all of its 3 components) are replaced by a number that starts from 1 and increases with every new attendee. But what I observe is that I get a Reg Code that is made of 4 components. Only the 3rd of which is an increasing number.
Can I have this reg code replaced completely? I don’t want the transaction id or the ticket id or anything else be part of the reg code.


<?php
/*
Plugin Name: A Change Regcode
Description: Dieses Plugin ändert den Registrierungscode von einer Veranstaltung in Event Espresso. Wenn Event Espresso deaktiviert wird, muss dieses Plugin auch deaktiviert werden.
Version: 1.1.0
Author: Sadik Özoguz
*/

function this_plugin_first() {
// ensure path to this file is via main wp plugin path
$wp_path_to_this_file = preg_replace('/(.*)plugins\/(.*)$/', WP_PLUGIN_DIR."/$2", __FILE__);
$this_plugin = plugin_basename(trim($wp_path_to_this_file));
$active_plugins = get_option('active_plugins');
$this_plugin_key = array_search($this_plugin, $active_plugins);
if ($this_plugin_key) { // if it's 0 it's the first plugin already, no need to continue
array_splice($active_plugins, $this_plugin_key, 1);
array_unshift($active_plugins, $this_plugin);
update_option('active_plugins', $active_plugins);
}
}
add_action("activated_plugin", "this_plugin_first");

//This code is not supported by Event Espresso
//This code is merely an example of how to use the filter FHEE__EE_Registration___generate_new_reg_code__new_reg_code

function change_the_reg_id($new_reg_code) {

//EE doesn't store sequential ID's so let's make an option to hold the last one.
$the_last_reg_id = get_option( 'my_current_reg_id' );

//if the option is not set, then let's make it 1
if( !isset($the_last_reg_id) ) {
$the_last_reg_id = '1';
}
//otherwise lets increment it and then update the option.
else {
$the_last_reg_id = (int)$the_last_reg_id + 1;
update_option( 'my_current_reg_id', $the_last_reg_id );
}

//modify the reg code with the new one and return it.
$new_reg_code = "2020-" . $the_last_reg_id;
return $new_reg_code;
}
add_filter('FHEE__EE_Registration_Processor___generate_reg_code__new_reg_code', 'change_the_reg_id', 10,2);


Tony

  • Support Staff

February 3, 2020 at 4:56 am

Hi there,

The EE_Registration_Processor::generate_reg_code() method (which runs the above filter) was deprecatd in version 4.9.1 in favour of the EventEspresso\core\domain\entities\RegCode class.

Inside that class is this filter:

apply_filters(
    'FHEE__Create__regCode__new_reg_code',
    implode('-', $this->reg_code),
    $transaction,
    $ticket
);

If you switch the above to use that filter it should work.

Note I don’t recommend changing the reg code to the above as it’s a little too generic, the current red code gives you details on what the registrations is linked to, your new one does not.

However, the filter is available and you are free to use it as you wish 🙂

Viewing 1 reply thread

The support post ‘Plugin to Change Reg-Code’ 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