I’m using woo-commerce with the membership and subscription extensions. I’m trying to display the expiration date of the current users subscription for which I need the subscription key to access it.
To find this key I need the product_id and order_id and (because these two values make up the key, “254_119” for example.). But when I try and access the current users order with
$order = new WC_Order(ID);
print_r($order);
The order data is empty, I tried to access the user_meta in the database as well before realising that it only contains shipping info and such.
Is it possible to access the current users most recent order? I’ve read that I may need to use
get_posts()
But I’m not sure of the parameters to access the data I require.
This doesn’t seem to work either.
$customer_orders = get_posts($order_count);
If I understand your question correctly, then approach should be :
Get most recent order of current User.
Now as we have most recent order, we can get
order_id
from that order.Now to get Products of that order, we can do as following :
Now we have both
product_id
andorder_id
so we can make a key :All Code together :
Let me know if you have any doubt.