GrünerAugust
GrünerAugust

Reputation: 31

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

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

Upvotes: 3

Views: 1894

Answers (1)

Kadament
Kadament

Reputation: 120

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;

Upvotes: 0

Related Questions