View Categories

WooCommerce:在结帐处添加“确认电子邮件地址”字段

< 1 min read

仿牌独立站出海专家


// ---------------------------------
// 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' );
    }
}