You can use woocommerce_order_status_changed
hooks. Using these hook you will get 3 params called $old_status
, $new_status
and $order_id
.
Then you just check is $new_status
is processing
or not. if processing then gets the order using $order_id
and then create a loop for line_items. For each line item, you will get product_id and check the product is publish or not. If Publish then just make the product in draft status, if not then just continue the loop.
Like the same procedure, you can also check for Completed status. If the status is completed just loop through the order items and make each product draft to publish.
Hope you understand. If not, then let me know. I will share the code snippet