Last active
October 30, 2023 07:26
-
-
Save SirDarcanos/87a24568a71ec185916bf2048d9d86a1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Add the Confirm Email Address field to the Billing checkout 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