Skip to content

Commit 2fcd8a1

Browse files
committed
refactor: remove global wpdb dependency and simplify bundle model initialization in OrderModel
1 parent 29dd942 commit 2fcd8a1

1 file changed

Lines changed: 4 additions & 10 deletions

File tree

models/OrderModel.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -633,8 +633,6 @@ public function mark_as_paid( $order_id, $note = '', $trigger_hooks = true ) {
633633
*
634634
* @since 3.0.0
635635
*
636-
* @global wpdb $wpdb WordPress database abstraction object.
637-
*
638636
* @param int $order_id The ID of the order to retrieve items for.
639637
*
640638
* @return array The order items, each containing details and course titles, or an empty array if no items are found.
@@ -647,13 +645,11 @@ public function get_order_items_by_id( $order_id ) {
647645
return $cached;
648646
}
649647

650-
global $wpdb;
651-
652-
$primary_table = "{$wpdb->prefix}tutor_order_items AS oi";
648+
$primary_table = 'tutor_order_items AS oi';
653649
$joining_tables = array(
654650
array(
655651
'type' => 'LEFT',
656-
'table' => "{$wpdb->prefix}posts AS p",
652+
'table' => 'posts AS p',
657653
'on' => 'p.ID = oi.item_id',
658654
),
659655
);
@@ -665,13 +661,11 @@ public function get_order_items_by_id( $order_id ) {
665661
$courses_data = QueryHelper::get_joined_data( $primary_table, $joining_tables, $select_columns, $where, array(), 'id', 0, 0 );
666662
$courses = $courses_data['results'];
667663

668-
if ( tutor()->has_pro ) {
669-
$bundle_model = new \TutorPro\CourseBundle\Models\BundleModel();
670-
}
664+
$bundle_model = tutor()->has_pro ? new \TutorPro\CourseBundle\Models\BundleModel() : null;
671665

672666
if ( ! empty( $courses_data['total_count'] ) ) {
673667
foreach ( $courses as &$course ) {
674-
if ( tutor()->has_pro && 'course-bundle' === $course->type ) {
668+
if ( is_object( $bundle_model ) && tutor()->bundle_post_type === $course->type ) {
675669
$course->total_courses = count( $bundle_model->get_bundle_course_ids( $course->id ) );
676670
}
677671

0 commit comments

Comments
 (0)