Skip to content

Commit

Permalink
Fix: Purchase history for membership based subscription plan is not s…
Browse files Browse the repository at this point in the history
…howing correct info
  • Loading branch information
Anindra123 committed Jan 15, 2025
1 parent 15a0955 commit 2a944ee
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
7 changes: 6 additions & 1 deletion models/OrderModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -484,11 +484,16 @@ public function get_order_items_by_id( $order_id ) {
'table' => "{$wpdb->prefix}posts AS p",
'on' => 'p.ID = oi.item_id',
),
array(
'type' => 'LEFT',
'table' => "{$wpdb->prefix}tutor_subscription_plans AS sp",
'on' => 'sp.id = oi.item_id',
),
);

$where = array( 'order_id' => $order_id );

$select_columns = array( 'oi.item_id AS id', 'oi.regular_price', 'oi.sale_price', 'oi.discount_price', 'oi.coupon_code', 'p.post_title AS title', 'p.post_type AS type' );
$select_columns = array( 'oi.item_id AS id', 'oi.regular_price', 'oi.sale_price', 'oi.discount_price', 'oi.coupon_code', 'p.post_title AS title', 'p.post_type AS type', 'sp.plan_name AS plan_name', 'sp.plan_type as plan_type' );

$courses_data = QueryHelper::get_joined_data( $primary_table, $joining_tables, $select_columns, $where, array(), 'id', 0, 0 );
$courses = $courses_data['results'];
Expand Down
16 changes: 11 additions & 5 deletions templates/dashboard/purchase_history.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Tutor\Helpers\DateTimeHelper;
use TUTOR\Input;
use Tutor\Models\OrderModel;
use TutorPro\Subscription\Models\PlanModel;

// Global variables.
$user_id = get_current_user_id();
Expand Down Expand Up @@ -103,7 +104,7 @@
<?php esc_html_e( 'Order ID', 'tutor' ); ?>
</th>
<th width="30%">
<?php esc_html_e( 'Course Name', 'tutor' ); ?>
<?php esc_html_e( 'Name', 'tutor' ); ?>
</th>
<th>
<?php esc_html_e( 'Date', 'tutor' ); ?>
Expand Down Expand Up @@ -138,15 +139,20 @@
<td>
<div class="tutor-fs-7">
<?php
$items = ( new OrderModel() )->get_order_items_by_id( $order->id );
$items = ( new OrderModel() )->get_order_items_by_id( $order->id );
$purchase_history_title = '';
foreach ( $items as $item ) {
$course_id = $item->id;
if ( OrderModel::TYPE_SUBSCRIPTION ) {
$course_id = apply_filters( 'tutor_subscription_course_by_plan', $item->id, $order );
if ( OrderModel::TYPE_SINGLE_ORDER !== $order->order_type ) {
$course_id = apply_filters( 'tutor_subscription_course_by_plan', $item->id, $order );
$is_course_plan = $item->plan_type && ! in_array( $item->plan_type, PlanModel::get_membership_plan_types(), true );
$purchase_history_title = $is_course_plan ? get_the_title( $course_id ) : $item->plan_name;
} else {
$purchase_history_title = get_the_title( $course_id );
}
?>
<li>
<?php echo esc_html( get_the_title( $course_id ) ); ?>
<?php echo esc_html( $purchase_history_title ); ?>
</li>
<?php
}
Expand Down

0 comments on commit 2a944ee

Please sign in to comment.