Sequential Reference Number Mail Tag for Contact Form 7
Adds a [_wpide_ref] mail tag that gives every Contact Form 7 submission a running reference number like WEB-1042, which you can quote in the subject or autoresponder.
Opens WPIDE on
Code
$wpide_cf7_ref_prefix = 'WEB-';
$wpide_cf7_ref_start = 1000;
add_filter( 'wpcf7_special_mail_tags', function ( $output, $name, $html = false ) use ( $wpide_cf7_ref_prefix, $wpide_cf7_ref_start ) {
if ( '_wpide_ref' !== $name ) {
return $output;
}
static $ref = null;
if ( null === $ref ) {
$next = max( (int) get_option( 'wpide_cf7_ref', $wpide_cf7_ref_start ), $wpide_cf7_ref_start ) + 1;
update_option( 'wpide_cf7_ref', $next, false );
$ref = $wpide_cf7_ref_prefix . $next;
}
return $ref;
}, 10, 3 );
Notes
Change the prefix and starting number at the top; the counter is shared by all forms and stored in an option.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.