I would like to "do something" (make a REST Request to a shipping company) after an order is completed (which happens on the edit order page by selecting a new status.).
Then "do something" and present the result (Success or Error) on this edit order page, maybe inside a meta box, maybe somewhere else.
I have tried this:
function do_something( $order_id ) {
// do something
echo "something was done";
}
add_action( 'woocommerce_order_status_completed', 'do_something', 20, 2 );
but I couldn't see any output in the edit order screen, so I think this must be coded differently. But how?
Half of the question ("write something in edit order page") has been answered here (1st answer): Display custom payment field in Woocommerce Admin, Orders and emails, like this:
function custom_field_admin_display_order_meta( $order ){
// do something
echo "something was done";
}
add_action(
'woocommerce_admin_order_data_after_shipping_address', 'custom_field_admin_display_order_meta', 10, 1 );
The other half of the question would be "only when status was changed to completed"...I still have no answer for that.
Thanks a lot!