Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 54 additions & 6 deletions classes/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -2657,6 +2657,49 @@ public function get_course_enrolled_ids_by_order_id( $order_id ) {
return false;
}

/**
* @param $order_id
*
* @return array
*
*/
public function get_subscriptions_by_order_id( $order_id ) {
global $wpdb;

// Return all children of a subscription
$args = array(
'post_parent' => $order_id,
'post_type' => 'shop_subscription'
);
return get_children($args);
}

/**
* @param $subscription_id
*
* @return object
*
*/
public function get_subscription_by_subscription_id( $subscription_id ) {
global $wpdb;

// Returns subscription information
$subscription = $wpdb->get_row(
$wpdb->prepare(
"SELECT subscriptions.*
FROM {$wpdb->prefix}woocommerce_order_items items
LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta meta
ON items.order_item_id = meta.order_item_id
AND meta.meta_key = '_product_id'
LEFT JOIN $wpdb->posts subscriptions
ON meta.meta_value = subscriptions.ID
WHERE `order_id` = %s
AND `order_item_type` = 'line_item'", $subscription_id
)
);
return $subscription;
}

/**
* Get wc product in efficient query
*
Expand Down Expand Up @@ -6020,14 +6063,21 @@ public function get_orders_by_user_id( $user_id = 0, $period = '', $start_date =
$post_type = '';
$user_meta = '';

if ( 'wc' === $monetize_by ) {
if ( 'wc' === $monetize_by || 'pmpro' === $monetize_by ) {
$post_type = 'shop_order';
$user_meta = '_customer_user';
} elseif ( 'edd' === $monetize_by ) {
$post_type = 'edd_payment';
$user_meta = '_edd_payment_user_id';
}

$add_join = '';
if ($monetize_by !== 'pmpro') {
$add_join = "INNER JOIN {$wpdb->postmeta} tutor_order
ON id = tutor_order.post_id
AND tutor_order.meta_key = '_is_tutor_order_for_course'";
}

$period_query = '';

if ( '' !== $period ) {
Expand All @@ -6054,11 +6104,9 @@ public function get_orders_by_user_id( $user_id = 0, $period = '', $start_date =
"SELECT {$wpdb->posts}.*
FROM {$wpdb->posts}
INNER JOIN {$wpdb->postmeta} customer
ON id = customer.post_id
AND customer.meta_key = '{$user_meta}'
INNER JOIN {$wpdb->postmeta} tutor_order
ON id = tutor_order.post_id
AND tutor_order.meta_key = '_is_tutor_order_for_course'
ON id = customer.post_id
AND customer.meta_key = '{$user_meta}'
{$add_join}
WHERE post_type = %s
AND customer.meta_value = %d
{$period_query}
Expand Down
10 changes: 9 additions & 1 deletion templates/dashboard/purchase_history.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
<tbody>
<?php foreach ( $orders as $order ) : ?>
<?php
if ( 'wc' === $monetize_by ) {
if ( 'wc' === $monetize_by || 'pmpro' === $monetize_by ) {
$wc_order = wc_get_order( $order->ID );
$price = tutor_utils()->tutor_price( $wc_order->get_total() );
$raw_price = $wc_order->get_total();
Expand Down Expand Up @@ -161,6 +161,14 @@
echo '<div>' . esc_html( get_the_title( $course['course_id'] ) ) . '</div>';
}
}
if ( $monetize_by === 'pmpro') {
$subscriptions = tutor_utils()->get_subscriptions_by_order_id( $order->ID );
if ( tutor_utils()->count( $subscriptions ) ) {
foreach ( $subscriptions as $subscription ) {
echo '<div>Subscription - ' . esc_html( tutor_utils()->get_subscription_by_subscription_id( $subscription->ID )->post_title ) . '</div>';
}
}
}
?>
</td>

Expand Down