Is there woocommerce function that will return me all related orders (at least the order ID) for the specific subscription that user has bough?
I have found in this official documentation Subscription Function & Property Reference:
WC_Subscription::get_related_orders( $return_fields, $order_type );
But this does not seem to be for specific subscription?
When ever I try to run it I get a fatal error no mater what I pass in:
Fatal error: Uncaught Error: Using $this when not in object context in C:\xampp\htdocs\mysite.com\wp-content\plugins\woocommerce-subscriptions\includes\class-wc-subscription.php:1413
I am making my own plugin and I select all subscriptions where post status = wc-active
from post table. I have looked in the "woocommerce_order_items
", "woocommerce_order_itemmeta
" and "postmeta
" tables but neither of them provide way to get related orders for user bought subscription...
If I only knew where are the relation for user bought subscriptions and its related orders, then i could write some sql but I have no idea and google does not yield any results either.
Any ideas?
My setup:
- php version 7.0.4
- wordpress version 4.7.3
- woocommerce 2.6.8
- woocommerce subscriptions: 2.0.18
It's very easy to get the order ID from subscription object. I am going to select, just like you, all subscriptions where
'post status' = 'wc-active'
from post table.You can also uncomment in the post query the
'meta_key'
and'meta_value'
array lines to get the subscriptions for one customer… This code is tested and works