1
votes

I have customized my WooCommerce checkout in functions.php to disable all billing address fields as my Stripe gateway does not require it.

I would like to allow customers to create an account during checkout too but it only asks for a username/password and wordpress accounts require an email. since I have disabled email in billing section the user cannot register.

I do not want the email address to stay in billing details as it will always show.

My ideal solution is having it in the account section.

How do I either

  1. move the email address from billing to the create an account section
  2. create an email address field for the account section?

Any help is appreciated.

enter image description here

1

1 Answers

1
votes

You can use woocommerce_checkout_fields hook

https://github.com/woocommerce/woocommerce/blob/4.1.0/includes/class-wc-checkout.php#L265

  • Get an array of checkout fields.

Add the following code to functions.php

// Add field
function filter_woocommerce_checkout_fields( $fields ) {    
    $fields['account']['billing_email'] = array(
        'label'        => __('E-mailadres', 'woocommerce'),
        'required'     => true,
        'type'         => 'email',
        'class'        => array('form-row-wide'),
        'validate'     => array('email'),
        'autocomplete' => 'email'
    );

    return $fields;
}
add_filter( 'woocommerce_checkout_fields' , 'filter_woocommerce_checkout_fields', 10, 1 );