Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/**
* Add the Confirm Email Address field to the Billing chekcout form
*/
add_filter( 'woocommerce_checkout_fields' , 'wc_custom_add_email_confirm_field_checkout' );
function wc_custom_add_email_confirm_field_checkout( $fields ) {
$fields['billing']['billing_email_confirm'] = array(
'label' => __( 'Confirm Email Address', 'domain' ),
'required' => true,
'class' => array( 'form-row-wide' ),
'priority' => 120,
);
return $fields;
}
/**
* Validate the Confirm Email Address field making sure that it matches the billing email.
*/
add_action( 'woocommerce_after_checkout_validation', 'wc_custom_check_matching_email_address', 10, 2 );
function wc_custom_check_matching_email_address( $data, $errors ) {
$billing_email = sanitize_email( $data['billing_email'] );
$confirm_billing = sanitize_email( $data['billing_email_confirm'] );
if ( ! empty( $confirm_billing ) && $billing_email !== $confirm_billing ) {
$errors->add( 'billing', __( 'Your email address does not match.', 'domain' ) );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment