如何在WooCommerce结帐中编辑我的帐户部分?

问题描述 投票:2回答:1

我在functions.php中自定义了我的WooCommerce结帐功能,以禁用所有账单地址字段,因为我的Stripe网关不需要它。

我也想允许客户在结帐期间创建一个帐户,但它只要求输入用户名/密码,而wordpress帐户则需要电子邮件。由于我在“结算”部分中禁用了电子邮件,因此用户无法注册。

我不希望该电子邮件地址保留在帐单详细信息中,因为它将始终显示。

我的理想解决方案是在帐户部分中添加它。

我怎么办

  1. 将电子邮件地址从帐单移至创建帐户部分
  2. 为帐户部分创建电子邮件地址字段?

感谢您的帮助。

enter image description here

php wordpress woocommerce field checkout
1个回答
1
投票

您可以使用woocommerce_checkout_fields挂钩

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

  • 获取检出字段的数组。

将以下代码添加到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 );
© www.soinside.com 2019 - 2024. All rights reserved.