您将允许用户填写电子邮件,使用它在数据库中查找用户id,然后将id用于订单。
一种可能的解决方案是更换function wc_create_new_customer( $email, $username = \'\', $password = \'\', $args = array() ) 具有自定义功能。
这是调用函数的地方,自定义函数需要做的就是找到正确的user\\u id。
protected function process_customer( $data ) {
$customer_id = apply_filters( \'woocommerce_checkout_customer_id\', get_current_user_id() );
if ( ! is_user_logged_in() && ( $this->is_registration_required() || ! empty( $data[\'createaccount\'] ) ) ) {
$username = ! empty( $data[\'account_username\'] ) ? $data[\'account_username\'] : \'\';
$password = ! empty( $data[\'account_password\'] ) ? $data[\'account_password\'] : \'\';
$customer_id = wc_create_new_customer(
$data[\'billing_email\'],
$username,
$password,
array(
\'first_name\' => ! empty( $data[\'billing_first_name\'] ) ? $data[\'billing_first_name\'] : \'\',
\'last_name\' => ! empty( $data[\'billing_last_name\'] ) ? $data[\'billing_last_name\'] : \'\',
)
);
if ( is_wp_error( $customer_id ) ) {
throw new Exception( $customer_id->get_error_message() );
}
wc_set_customer_auth_cookie( $customer_id );
// As we are now logged in, checkout will need to refresh to show logged in data.
WC()->session->set( \'reload_checkout\', true );
// Also, recalculate cart totals to reveal any role-based discounts that were unavailable before registering.
WC()->cart->calculate_totals();
}
希望这能帮助你找到正确的方向。
干杯,加布里埃尔