简体   繁体   中英

How to edit my account section in WooCommerce checkout?

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.

在此处输入图像描述

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 );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM