skip to Main Content

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


  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:

    Login or Signup to reply.
  2. Some details can be obtained directly from the WC_ subscription object using the following methods

     $subscription->get_id() //subscription id
     $subscription->get_parent_id() //order id
     $subscription->get_currency()
     $subscription->get_customer_note()
     $subscription->get_prices_include_tax()
     $subscription->get_payment_method()
     $subscription->get_payment_method_title()
     $subscription->get_billing_first_name()
     $subscription->get_billing_last_name()
     $subscription->get_billing_company()
     $subscription->get_billing_address_1()
     $subscription->get_billing_address_2()
     $subscription->get_billing_city()
     $subscription->get_billing_state()
     $subscription->get_billing_postcode()
     $subscription->get_billing_country()
     $subscription->get_billing_email()
     $subscription->get_billing_phone()
     $subscription->get_shipping_first_name()
     $subscription->get_shipping_last_name()
     $subscription->get_shipping_company()
     $subscription->get_shipping_address_1()
     $subscription->get_shipping_address_2()
     $subscription->get_shipping_city()
     $subscription->get_shipping_state()
     $subscription->get_shipping_postcode()
     $subscription->get_shipping_country()
     $subscription->get_order_key()
     $subscription->get_date_created()
     $subscription->get_date_modified()
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search