• Resolved Ibby

    (@ibby)


    Dear Fluid Checkout,

    Is it possible to make the confirm email address field mandatory for guest users?

    Thank you.

Viewing 1 replies (of 1 total)
  • Plugin Author Diego Versiani

    (@diegoversiani)

    Hi @ibby,

    It is possible to accomplish this with custom code (below), however, we do not recommend it as this additional confirmation field might add friction to the checkout process and trigger more abandoned carts.

    /**
    * Add email confirmation field and set instant validation for the email confirmation.
    */
    function fluidcheckout_add_email_confirmation_field_checkout( $fields ) {
    // Bail if billing section or email field not present
    if ( ! array_key_exists( 'billing', $fields ) || ! array_key_exists( 'billing_email', $fields[ 'billing' ] ) ) { return $fields; }

    $fields[ 'billing' ][ 'billing_email' ][ 'class' ] = array( 'form-row-first' );
    $fields[ 'billing' ][ 'billing_email_confirmation' ] = array(
    'label' => 'Confirm Your Email Address',
    'required' => true,
    'class' => array( 'form-row-last', 'validate-email' ),
    'clear' => true,
    'priority' => 6, // The main billing email field is set with priority 5 with Fluid Checkout
    );

    // Set confirmation validation attributes for the email field
    if ( ! array_key_exists( 'custom_attributes', $fields[ 'billing' ][ 'billing_email_confirmation' ] ) ) { $fields[ 'billing' ][ 'billing_email_confirmation' ][ 'custom_attributes' ] = array(); }
    $fields[ 'billing' ][ 'billing_email_confirmation' ][ 'custom_attributes' ][ 'data-confirm-with' ] = '#billing_email';

    return $fields;
    }
    add_filter( 'woocommerce_checkout_fields' , 'fluidcheckout_add_email_confirmation_field_checkout', 1100 );



    /**
    * Validate whether email and confirmation fields values match.
    */
    function fluidcheckout_matching_email_address_field_validation() {
    // Get email field values
    $email_value = $_POST[ 'billing_email' ];
    $email_confirmation_value = $_POST[ 'billing_email_confirmation' ];

    // Maybe add error message if values do not match
    if ( $email_value !== $email_confirmation_value ) {
    wc_add_notice( __( 'Your email address and confirmation do not match.', 'your-text-domain' ), 'error' );
    }
    }
    add_action( 'woocommerce_checkout_process', 'fluidcheckout_matching_email_address_field_validation', 10 );



    /**
    * Move fields to the contact substep.
    */
    function fluidcheckout_move_fields_to_contact_substep( $contact_field_ids ) {
    // Fields after existing fields
    $contact_field_ids = array_merge( $contact_field_ids, array( 'billing_email_confirmation' ) );
    return $contact_field_ids;
    }
    add_filter( 'fc_checkout_contact_step_field_ids', 'fluidcheckout_move_fields_to_contact_substep', 10 );



    /**
    * Maybe set contact step as incomplete if email and confirmation fields do not match value.
    */
    function fluidcheckout_maybe_set_contact_step_incomplete( $is_step_complete ) {
    // Get email field values
    $email_value = WC()->checkout->get_value( 'billing_email' );
    $email_confirmation_value = WC()->checkout->get_value( 'billing_email_confirmation' );

    // Maybe set as incomplete if fields do not match
    if ( $email_value !== $email_confirmation_value ) {
    $is_step_complete = false;
    }

    return $is_step_complete;
    }
    add_filter( 'fc_is_step_complete_contact', 'fluidcheckout_maybe_set_contact_step_incomplete', 10 );



    /**
    * Add email confirmation field in the list of fields to skip adding to substep review text lines.
    */
    function fluidcheckout_add_confirmation_field_skip_substep_text_lines( $skip_fields ) {
    $skip_fields[] = 'billing_email_confirmation';
    return $skip_fields;
    }
    add_filter( 'fc_substep_text_contact_field_keys_skip_list', 'fluidcheckout_add_confirmation_field_skip_substep_text_lines', 10 );

    If you are unsure about how to add the code snippet to your website, check our article:
    How to safely add code snippets to your WooCommerce website

    Please note that this type of customization is not covered by our support scope, so you will have to make any changes to this code snippet by yourself.

    I’m closing this ticket for now.

    Best,
    Diego.

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.