after wrestling with this issue for 2 days now, i found it: there is two hooks, one before and one after saving:
- woocommerce_before_save_order_items
- woocommerce_saved_order_items
both are fired when saving an order in the backend. one before the save and one afterwards.
both two hooks carry the same variables: $order_id (int) & $items (array)
i guess with the first hook, you could get the old order and compare its contents with the items array to see what has changed. at least this is what i try to accomplish now.
so this is how you would trigger this:
add_action( 'woocommerce_before_save_order_items', 'so42270384_woocommerce_before_save_order_items', 10, 2 );
function so42270384_woocommerce_before_save_order_items( $order_id, $items ) {
echo $order_id;
var_dump( $items );
}
be aware..
adding a product to an exitsting order does implement another hook that gets called before this (so when hitting SAVE, the above function will fire, but the order and its items are already set BEFORE saving (when adding a product, the order will save immediately). that means $order = new WC_Order( $order_id );
will have the new items already in it, before and after, so there is no way to find, what has changed.). but the woocommerce_ajax_add_order_item_meta
hook is triggered on 'add product' and helped me on that end. happy coding everyone..