Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save zackeryfretty/c0ee2445054ee3b45a4a2a16ed33c23a to your computer and use it in GitHub Desktop.
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).
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