如何从 WC_Subscription 实例对象中获取用户 ID [英] How to get the user ID from a WC_Subscription instance Object

查看:36
本文介绍了如何从 WC_Subscription 实例对象中获取用户 ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个功能需要帮助,希望可以处理我的订阅任务.代码注释 (//...) 是我想要弄清楚的.如果您有其他反馈意见,我也愿意接受.

I have two functions I need help with that I hope can handle my subscription tasks. The code comments (// ...) is what I'm trying to figure out. If you have other feedback, I'm open to them as well.

用于完成初始订阅付款和订阅续订.

This one for completed initial subscription payments and subscription renewals.

function payment_made($subscription){
    // How do I get the User ID from subscription? (Definitely need this)
}
add_action("woocommerce_subscription_payment_complete", "payment_made");

当状态发生变化时,我可以处理手动和系统更改,无论是手动覆盖还是失败/待处理/活动/基于付款或切换的任何状态.

And this one for when a status is changed, so I can handle manual and system changes either manual overrides or failed/pending/active/whatever status based of payments or switches.

function status_update($subscription, $old_status, $new_status){
    // How do I get the User ID from subscription (Definitely need this)
}
add_action("woocommerce_subscription_status_updated", "status_updated");

推荐答案

要从 WC_Subscription 对象中获取用户 ID,您将使用 get_user_id() 方法,就像您可以使用 WC_Order 对象:

To get the user id from the WC_Subscription Object, you will use get_user_id() method just as you can do with a WC_Order Object:

$user_id = $subscription->get_user_id();

经过测试并有效.

相关:

这篇关于如何从 WC_Subscription 实例对象中获取用户 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆