我正在使用woomerce订阅插件,我正在尝试获取给定wc_订阅的客户或用户id。
下面是我一直在使用但失败的代码:
add_action( 'woocommerce_scheduled_subscription_trial_end', 'registration_trial_expired', 100 );
function registration_trial_expired( $wc_subscription ) {
mail("[email protected]", "Expired", "Someone's order has expired");
$userid = $wc_subscription->customer_user;
mail("[email protected]", "Expired", "Someone's order has expired with customer".$userid);
...
}
我以为
$wc_subscription->customer_user
会有用户id,但它是空的。事实上阻止了代码的继续。如何获取用户ID为
$wc_subscription
? 最佳答案
WCXEclipse是WCYORD的扩展版本,因此可以使用与WCYORD相同的调用。
你的代码调整了:
add_action( 'woocommerce_scheduled_subscription_trial_end', 'registration_trial_expired', 100 );
function registration_trial_expired( $wc_subscription )
{
$order_billing_email = $wc_subscription->get_billing_email();
$User = get_user_by( 'email', $order_billing_email ); /
$FirstName = $User->first_name;
$LastName = $User->last_name;
$UserId = $User->ID;
}