Created
February 23, 2017 20:30
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the
woocommerce_order_status_completed
hook only works for certain payment methods, so you need to figure out the right hooks accoring to your requirements.