// ---------------------------------
// 1) Make original email field half width
// 2) Add new confirm email field
add_filter( 'woocommerce_checkout_fields' , 'bbloomer_add_email_verification_field_checkout' );
function bbloomer_add_email_verification_field_checkout( $fields ) {
$fields['billing']['billing_email']['class'] = array( 'form-row-first' );
$fields['billing']['billing_em_ver'] = array(
'label' => 'Confirm mail Address',
'required' => true,
'class' => array( 'form-row-last' ),
'clear' => true,
'priority' => 999,
);
return $fields;
}
// ---------------------------------
// 3) Generate error message if field values are different
add_action('woocommerce_checkout_process', 'bbloomer_matching_email_addresses');
function bbloomer_matching_email_addresses() {
$email1 = $_POST['billing_email'];
$email2 = $_POST['billing_em_ver'];
if ( $email2 !== $email1 ) {
wc_add_notice( 'Your email addresses do not match', 'error' );
}
}
How can we help you?
WooCommerce:在结帐处添加“确认电子邮件地址”字段
< 1 min read