如何从 WC_Subscription 实例对象获取订单详细信息 [英] How to get Order Details from a WC_Subscription instance Object
问题描述
用于完成初始订阅付款和订阅续订.
This one for completed initial subscription payments and subscription renewals.
function payment_made($subscription){
// How do I get the order details?
}
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 order details?
}
add_action("woocommerce_subscription_status_updated", "status_updated");
推荐答案
要从 WC_Subscription
对象中获取订单详细信息,您首先需要获取父 ID(即订单 ID)使用 get_parent_id()
方法:
To get the Order details from the WC_Subscription
Object, you will need first to get the parent ID (which is the order ID) using get_parent_id()
method:
$order_id = $subscription->get_parent_id();
然后您将使用以下命令从订单 ID 中获取 WC_Order 对象:
Then you will get the WC_Order Object from the order Id using:
$order = wc_get_order( $order_id );
然后获取订单详情:如何获取WooCommerce订单详情
相关:
这篇关于如何从 WC_Subscription 实例对象获取订单详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!