Is there a way to get from $product
from $subscription
?
Thanks to this post, I know that from $subscription
I can get $o
Yes, if you have a "subscription ID" you can get an object like this:
$subscription = new WC_Subscription( $the_id );
When you already have $subscription object:
$related_orders_ids_array = $subscription->get_related_orders();
Then loop through array of related orders.
foreach ( $related_orders_ids_array as $order_id ) {
$order = new WC_Order( $order_id );
$items = $order->get_items();
then if you loop through order items, you can access product information:
foreach ( $items as $product ) {
var_dump( $product );
}
}