How to get Order Details from a WC_Subscription instance Object

后端 未结 2 1742
隐瞒了意图╮
隐瞒了意图╮ 2021-01-26 12:08

This one for completed initial subscription payments and subscription renewals.

function payment_made($subscription){
    // How do I get the order details?
}
add         


        
2条回答
  •  醉酒成梦
    2021-01-26 13:14

    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

提交回复
热议问题