You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
["FEAT"] Pass the order to a completed when enroll is successful #116
Is your feature request related to a problem? Please describe.
When you create an Open edX course as a product in WooCommerce, following the documentation, and then you place an order and pay, the order changes from pending payment to processing. When this occurs, the creation of an enrollment request is triggered. The idea is to create a flow that, when an enrollment request is created and the enrollment is successful, triggers a change in the status of the order from processing to completed. To have another clear view of the enrollments that were made successful and those that may need intervention.
Describe the solution you'd like
If the enrollment request has been successfully created the enrollment, change the order to a completed state.
Note: we need to take into account that in an order, we can have several courses, and also we can have products that are not open edx courses.
Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
Additional context
Add any other context or screenshots about the feature request here.
Goal:
Automatically update the WooCommerce order status from processing to completed only if the order contains at least one Open edX course product, identified by the "_course_id" meta key with a non-empty value.
Hooks Used:
woocommerce_order_status_changed:
Purpose: Wait for WooCommerce to process the order and let the Open edX plugin do its thing (enrollment, notes, etc.).
woocommerce_thankyou:
Purpose: Finalize the order. If the order contains Open edX course products and the status is still processing, change it to completed.
Flow:
Retrieve the Order:
Get the order object using the $order_id passed to the woocommerce_thankyou hook.
Check Order Status:
Make sure the order is in the processing state before proceeding.
Loop Through Order Items:
Iterate over $order->get_items() and check for the existence of the "_course_id" meta key on each item.
Determine Enrollment Relevance:
If any item has a non-empty _course_id, it’s assumed to be a course product, and an enrollment request would have been initiated (and hopefully succeeded at this stage).
Update Order Status:
If the above condition is true, update the order status to completed and optionally add an order note.
Notes: Currently, if the order only has an open edx course as a product, the status goes to processing (because it may require some operations to ensure we don't have anything pending to deliver to the customer).
The idea is to change the status to complete if and only if all the elements in the orders were delivered.
As you mentioned, we need to make sure we comply with the condition that enrollment is made before changing the status.
And I suggest we take into account the edge cases to ensure we avoid false positives (marking something as completed that is not).
@MaferMazu Thank you for the valuable feedback — I completely agree with your points.
You're right that changing the status to "completed" should only happen after confirming successful enrollment.
Additionally, I’ll ensure that the logic only runs for orders that contain only an open edX course as a product, thereby avoiding premature completion of orders that involve physical products or pending deliveries.
I'll revisit the flow to cover those edge cases and ensure we’re not marking orders as complete unless everything has been fully delivered.
If any physical product is present, the order will remain in "processing" and must be completed manually from the WooCommerce order screen.
Appreciate the guidance — I’ll revise the implementation accordingly.
Activity
amirnafees88 commentedon Aug 6, 2025
Hi @MaferMazu ,
Please assign this issue to me — I’d like to work on it as part of community support.
amirnafees88 commentedon Aug 6, 2025
Goal:
Automatically update the WooCommerce order status from processing to completed only if the order contains at least one Open edX course product, identified by the "_course_id" meta key with a non-empty value.
Hooks Used:
woocommerce_order_status_changed:
Purpose: Wait for WooCommerce to process the order and let the Open edX plugin do its thing (enrollment, notes, etc.).
woocommerce_thankyou:
Purpose: Finalize the order. If the order contains Open edX course products and the status is still processing, change it to completed.
Flow:
Retrieve the Order:
Get the order object using the $order_id passed to the woocommerce_thankyou hook.
Check Order Status:
Make sure the order is in the processing state before proceeding.
Loop Through Order Items:
Iterate over $order->get_items() and check for the existence of the "_course_id" meta key on each item.
Determine Enrollment Relevance:
If any item has a non-empty _course_id, it’s assumed to be a course product, and an enrollment request would have been initiated (and hopefully succeeded at this stage).
Update Order Status:
If the above condition is true, update the order status to completed and optionally add an order note.
MaferMazu commentedon Aug 6, 2025
@amirnafees88, thanks for contributing to this.
__
Notes: Currently, if the order only has an open edx course as a product, the status goes to processing (because it may require some operations to ensure we don't have anything pending to deliver to the customer).
The idea is to change the status to complete if and only if all the elements in the orders were delivered.
As you mentioned, we need to make sure we comply with the condition that enrollment is made before changing the status.
And I suggest we take into account the edge cases to ensure we avoid false positives (marking something as completed that is not).
amirnafees88 commentedon Aug 7, 2025
@MaferMazu Thank you for the valuable feedback — I completely agree with your points.
You're right that changing the status to "completed" should only happen after confirming successful enrollment.
Additionally, I’ll ensure that the logic only runs for orders that contain only an open edX course as a product, thereby avoiding premature completion of orders that involve physical products or pending deliveries.
I'll revisit the flow to cover those edge cases and ensure we’re not marking orders as complete unless everything has been fully delivered.
If any physical product is present, the order will remain in "processing" and must be completed manually from the WooCommerce order screen.
Appreciate the guidance — I’ll revise the implementation accordingly.
amirnafees88 commentedon Aug 12, 2025
@MaferMazu Here is the PR. Kindly review.