woocommerce
woocommerce copied to clipboard
[Enhancement]: Trigger hook 'woocommerce_order_status_completed' after order status set to 'completed' through WooCommerce API
Describe the solution you'd like
Currently, when setting an order's status to 'completed' manually, the hook 'woocommerce_order_status_completed' is triggered, but when done through the WooCommerce API it is not.
Doing this through WooCommerce's API as well will improve compatibility with plugins that rely on this hook, for instance:
A client of ours has a webshop that uses a plug-in that relies on the hook 'woocommerce_order_status_completed' to enqueue a review-invitation email to be send after a week of a customer's order. The order status is set to 'completed' through WooCommerce's API, by an external shipping solution called SendCloud.
I understand that it's easier said than done, because triggering the hook is something done through using the WordPress backend, which would mean that WooCommerce's API would have to fetch a backend URL in order to trigger the hook, which is not efficient.
Perhaps a more efficient solution would be for WooCommerce's API to add order ID's to some database table that will then be used by a cron job to fetch the backend URL and trigger the hook for a batch of order ID's.
For now I will manually enqueue the review-invitation emails, but regardless I think it would be a great improvement to the API.
Describe alternatives you've considered
No response
Additional context
No response
@webr459g8s490ghw3 I was just testing this out, and was able to trigger the woocommerce_order_status_completed action hook when changing an order status to "completed" through the API (the wc/v3/orders endpoint). Can you describe a step-by-step of what you're doing when that hook is not firing?
@webr459g8s490ghw3 I was just testing this out, and was able to trigger the
woocommerce_order_status_completedaction hook when changing an order status to "completed" through the API (thewc/v3/ordersendpoint). Can you describe a step-by-step of what you're doing when that hook is not firing?
As I can see now, the Legacy API is enabled. Could this be the reason for the hook not firing? I am not sure why it is enabled, so I would have to discuss this with the team before disabling it.
@webr459g8s490ghw3 just to clarify, you're using a legacy endpoint (i.e. wc-api/v3/orders) rather than the current REST API endpoint? If so, I definitely encourage you to update the current version.
As a part of this repository's maintenance, this issue is being marked as stale due to inactivity. Please feel free to comment on it in case we missed something.
After 7 days with no activity this issue will be automatically closed.
This issue was closed because it has been 14 days with no activity.