Confirm email address in WooCommerce checkout page

// Add "Confirm email address" field in WooCommerce checkout page
add_filter( 'woocommerce_checkout_fields' , 'add_checkout_email_verification_field' );
   
function add_checkout_email_verification_field( $fields ) {
  
$fields['billing']['billing_email']['class'] = array( 'form-row-full' );
  
$fields['billing']['billing_em_ver'] = array(
    'label' => 'Confirm Email address',
    'required' => true,
    'class' => array( 'form-row-full' ),
    'clear' => true,
    'priority' => 999,
);
  
return $fields;
}

// Generate error message if field values are different
  
add_action('woocommerce_checkout_process', 'email_validation');
  
function email_validation() { 
    $email1 = $_POST['billing_email'];
    $email2 = $_POST['billing_em_ver'];
    if ( $email2 !== $email1 ) {
        wc_add_notice( 'Your email addresses do not match (check for capital letters, spaces or any other errors)', 'error' );
    }
}

Only run on site front-end