Skip to content

Commit

Permalink
enroll to bundle courses only for single purchase bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
harunollyo committed Jan 20, 2025
1 parent 787bdd6 commit eec9d8d
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions ecommerce/HooksHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,9 @@ public function manage_earnings_and_enrollments( string $order_status, int $orde
// Update enrollment status based on order status.
$update = tutor_utils()->update_enrollments( $enrollment_status, array( $has_enrollment->ID ) );
if ( $update ) {
if ( $this->is_bundle_order( $order, $object_id ) ) {
if ( $this->is_bundle_order( $order, $object_id ) && $this->order_model->is_single_order( $order ) ) {
if ( 'completed' === $enrollment_status ) {
BundleModel::enroll_to_bundle_courses( $object_id, $student_id );
do_action( 'tutor_order_enrolled', $order, $has_enrollment->ID );
} else {
BundleModel::disenroll_from_bundle_courses( $object_id, $student_id );
}
Expand All @@ -337,7 +336,7 @@ public function manage_earnings_and_enrollments( string $order_status, int $orde
/**
* For subscription, renewal no need to update order id.
*/
if ( $this->order_model::TYPE_SINGLE_ORDER === $order->order_type ) {
if ( $this->order_model->is_single_order( $order ) ) {
update_post_meta( $has_enrollment->ID, '_tutor_enrolled_by_order_id', $order_id );

/**
Expand Down Expand Up @@ -366,21 +365,19 @@ public function manage_earnings_and_enrollments( string $order_status, int $orde
do_action( 'tutor_after_enrolled', $object_id, $student_id, $has_enrollment->ID );
}
}

if ( 'completed' === $enrollment_status ) {
do_action( 'tutor_order_enrolled', $order, $has_enrollment->ID );
}
}
} else {
if ( $order->order_status === $this->order_model::ORDER_COMPLETED ) {
// Insert enrollment.
add_filter(
'tutor_enroll_data',
function( $enroll_data ) {
$enroll_data['post_status'] = 'completed';
return $enroll_data;
}
);
add_filter( 'tutor_enroll_data', fn( $enroll_data) => array_merge( $enroll_data, array( 'post_status' => 'completed' ) ) );

$enrollment_id = tutor_utils()->do_enroll( $object_id, $order_id, $student_id );
if ( $enrollment_id ) {
if ( $this->is_bundle_order( $order, $object_id ) ) {
if ( $this->is_bundle_order( $order, $object_id ) && $this->order_model->is_single_order( $order ) ) {
BundleModel::enroll_to_bundle_courses( $object_id, $student_id );
}
update_post_meta( $enrollment_id, '_tutor_enrolled_by_order_id', $order_id );
Expand Down

0 comments on commit eec9d8d

Please sign in to comment.