How to get Order Details from a WC_Subscription instance Object

≡放荡痞女 提交于 2020-07-31 05:48:57

问题


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");

回答1:


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();

Then you will get the WC_Order Object from the order Id using:

$order = wc_get_order( $order_id );

Then to get order details: How to get WooCommerce order details

Related:

  • How to get the user ID from a WC_Subscription instance Object
  • How to get the Product ID from a WC_Subscription instance Object


来源:https://stackoverflow.com/questions/63043448/how-to-get-order-details-from-a-wc-subscription-instance-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!