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");
2
Answers
To get the Order details from the
WC_Subscription
Object, you will need first to get the parent ID (which is the order ID) usingget_parent_id()
method:Then you will get the WC_Order Object from the order Id using:
Then to get order details: How to get WooCommerce order details
Related:
Some details can be obtained directly from the WC_ subscription object using the following methods