如何获取客户创建挂钩中的订单信息?

How to get the order information inside the customer creation hook?

当访客在我的 WooCommerce 商店购买新产品时,我使用 woocommerce_created_customer 挂钩在外部数据库上创建一个新用户,其中包含我从 $customer_id, $new_customer_data, $password_generated 参数中获得的一些信息.

例如:

function action_woocommerce_created_customer($customer_id, $new_customer_data, $password_generated) {
    // Create a new user on external database
}
add_action('woocommerce_created_customer', 'action_woocommerce_created_customer', 10, 3);

嗯。我需要的是连接到当前订单以获取订单 ID。在我的商店中,只能结合订单创建用户帐户。有没有办法在 woocommerce_created_customer 挂钩中获取订单信息?还是这个 do_action 只是在订单完成之前调用的?

我考虑过支付完成后使用另一个钩子。但这在我的情况下是不可能的,因为这是我找到的唯一可以获取我非常需要的未经哈希处理的用户密码的挂钩。

您知道如何在客户创建挂钩中获取订单信息吗?

订单是在客户之后创建的。

$this->process_customer( $posted_data );
$order_id = $this->create_order( $posted_data );
$order    = wc_get_order( $order_id );

使用这个钩子来完成任务。

do_action( 'woocommerce_checkout_order_processed', $order_id, $posted_data, $order );

$posted_data包含用户名和密码

$username    = ! empty( $posted_data['account_username'] ) ? $posted_data['account_username'] : '';
$password    = ! empty( $posted_data['account_password'] ) ? $posted_data['account_password'] : '';