How to get the WooCommerce Subscription parent ID in the renewal order admin email?

1.4k views Asked by At

Because we send our WC Order Mails straight to our CRM i need the Subscription parent ID of the subscription renewals like echo 'shop_orderid===' . $order->id . '___<br>'; // Order ID

I found $parent_id = $order->get_parent_id(); but that doesnt work - i just get a 0 ...

BR Alex

1

There are 1 answers

0
Kadament On

You can get the parent order ID from the renewal ID by first getting the subscriptions that are associated with the renewal order (it returns as an array but there will be only 1 as each renewal order is specific to a subscription), and then by getting the (parent) order ID from the subscription.

$parentOrderID = '';

$orderID = $orderObj->get_id();
    
$subscriptions = wcs_get_subscriptions_for_order($orderID, ['order_type' => 'any']);
    
foreach ($subscriptions as $subscriptionID => $subscriptionObj) {

    $parentOrderID = $subscriptionObj->order->get_id();

}
    
echo $parentOrderID;