Created
June 14, 2024 21:04
-
-
Save zackeryfretty/c0ee2445054ee3b45a4a2a16ed33c23a to your computer and use it in GitHub Desktop.
Passing the "Subscription ID" to this function when exporting WooCommerce Subscriptions via WP All Export will build a comma separated list of the items the subscription (which isn't included by default).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function zf_get_recent_subscription_order_items( $id ){ | |
if ( is_nan( $id ) ) { | |
return ''; | |
} | |
$subscription = new WC_Subscription( $id ); | |
$related_orders = $subscription->get_related_orders(); | |
$recent_order_id = current( $related_orders ); | |
$recent_order = wc_get_order( $recent_order_id ); | |
$order_items = $recent_order->get_items(); | |
$output = ''; | |
foreach ( $order_items as $order_item ) { | |
$output .= $order_item->get_name() . ', '; | |
} | |
$output = rtrim( $output, ', ' ); | |
return $output; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment