Search code examples
wordpresswoocommercesubscription

Get WooCommerce Subscription Original (Initial) order number


I am working on a project where a user would purchase a subscription and when they do we send data to another server using API calls. Once the server receives the necessary information it creates a serial number and sends it back to the woocommerce site.

This all works just fine, I am successful in sending data and retrieving serial numbers and synchronizing most things on the server.

I am stuck at when Woo Subscriptions renews their order I need to update information on the other server regarding the serial number. I think I would be fine if I could get access to the original order number.

The other issue I am running into is determining if the order is in fact a renewal order, I have a trivial flag set up that checks if "subscription_interval" is inside of the order->get_items, if not then its a renewal order. Something is just fishy about this whole thing.

Basically I need a way to find out if it is a renewal order and if it is give me the initial order number.

Looking at the order screen on the very bottom of the metaboxes (advanced) there is a metabox that shows "Related Subscription Orders" and even shows the initial order. How can I access this data?

Thanks in advance!


Solution

  • Ok, so I found WC_Subscriptions_Renewal_Order and ran a get_class_methods on it. I found is_renewal and get_parent_order_id, life is good again :)