Skip to content

Instantly share code, notes, and snippets.

@niemenmaa
Created February 23, 2017 20:30
Show Gist options
  • Save niemenmaa/545e5f738027c6e36637f49c6ccd2743 to your computer and use it in GitHub Desktop.
Save niemenmaa/545e5f738027c6e36637f49c6ccd2743 to your computer and use it in GitHub Desktop.
This snippet moves ordered items in draft state when order is marked complete. Same with category filter: https://gist.github.com/Pikkulahti/2504f6539b67efe417bd9b1382f72658
<?php
/**
* Moves ordered items in draft state.
*/
function custom_draft_complete_orders( $order_id ) {
// Fetch order infromation
$order = new WC_Order( $order_id );
// Get products on order
$items = $order->get_items();
// Loop through products
foreach ( $items as $product ) {
// Change status to draft
wp_update_post(
array(
'ID' => $product['product_id'],
'post_status' => 'draft',
)
);
}
}
add_action( 'woocommerce_order_status_completed', 'custom_draft_complete_orders');
@niemenmaa
Copy link
Author

the woocommerce_order_status_completedhook only works for certain payment methods, so you need to figure out the right hooks accoring to your requirements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment