Add an Email Confirmation Field

Sometimes you may find that you want to add a second email field for requiring that the buyer confirms their email address by entering it twice. This is really quite simple to do, just paste the following snippet into your functions.php or any custom plugin:

<?php

function pw_edd_add_email_confirmation() {
	?>
 	<p>
		<input class="edd-input required" type="email" name="edd_email_confirm" placeholder="<?php _e('Confirm email address', 'edd'); ?>" id="edd-emai-confirml" value=""/>
		<label class="edd-label" for="edd-email-confirm"><?php _e('Confirm Your Email Address', 'edd'); ?></label>
 	</p>
	<?php	
}
add_action('edd_purchase_form_after_email', 'pw_edd_add_email_confirmation');

function pw_edd_process_email_confirmation($valid_data, $data) {
	if( !isset($data['edd_email_confirm'] ) || !is_email( $data['edd_email_confirm'] ) ) {
		edd_set_error( 'email_confirmation_required', __( 'Please confirm your email', 'edd' ) );
	}
	if( trim( $data['edd_email_confirm'] ) != trim( $data['edd_email'] ) ) {
		edd_set_error( 'email_confirmation_required', __( 'Your email addresses do not match', 'edd' ) );
	}
}
add_action('edd_checkout_error_checks', 'pw_edd_process_email_confirmation', 10, 2);

Comments

  1. Think it’s imperative to have customer confirm their email address, but exactly which function.php file should this code, edd_email_conf.php be added, and where in that file. Thanks
    I got it to work when I was logged in but not when not logged as this brings up a login page.

    Reply

  2. Sorry mate, the function.php displays differently to the code. if it will help you, I’ll find a way to put it up on my server.

    Reply

  3. Yeah, regretted doing that the moment I entered it, sorry.

    I have tried to add your snippet to the very beginning of my theme’s function.php and at its end – neither worked, error in both cases

    Here’s weaver 2010 function.php code. Cannot find a guest login enable/disable in Weaver’s setup options. Sorry to bug you, but seems a good feature as the customer can only get his product via the email link.

    http://snippi.com/s/1qa6awy

    Reply

  4. Jack

    the box is not checked.
    If I add the snippet to any of your function.php files, wordpress won’t accept and disbles the plugin

    If I add the snippet at the begging of the theme’s function.php
    Parse error: syntax error, unexpected ‘<' in /home1/jackand6/public_html/wordpress/wp-content/themes/2010-weaver/functions.php on line 23

    If added at the end, similar but different line number.

    Reply

  5. Benuz

    Hi there.
    I wanted to put adress fields on the checkout form and not a confirmation for the email adress. Could you tell me where I have to change what to get it done? Im not that fermiliar with php :/

    I want an input field with “street and number” of the house and another field for “zip code and city”

    Would be nice if you could help me with that.

    Reply

  6. Pippin,
    As a (very) new user to edd and WordPress, find your examples really helpful.

    Just noticed a minor typo in Line 6 of function pw_edd_add_email_confirmation() {

    Line 6 : </

    ( "Confirm your Eail Address" should read "Confirm your Email Address" ) .

    General comment:
    As the buyer will receive the download link via email, seems pretty essential that it’s correct.
    Would favour the checkout form defaulting to a ‘Confirm Email entry’, instead of adding function.

    An asterisk to denote ‘mandatory entries’ would be ‘nice to have’ too.

    Reply

  7. Hello Pippin;

    Thank you for your php code.
    I inserted this code in my child theme’s function.php. But when i test it on the website I get “Error: Please confirm your email” I made sure I entered the same email twice by cutting and pasting. But still get the error. What could be wrong?

    Thanks!
    BJ

    Reply

  8. I’m trying to get this to work, not familiar much with php forms,

    Could you please direct me where to paste the following snippet inside my functions.php file?

    Is it alright to paste them right in the end of the line of my functions.php file? after ‘ ?> ‘
    Like this:

    ?>
    <?php

    function pw_edd_add_email_confirmation() {……………………………………….
    …………………………….
    …………………………….

    OR In the beginning?

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>