Skip to content

Commit

Permalink
Merge pull request woocommerce#9290 from woothemes/issue/9166-reset-o…
Browse files Browse the repository at this point in the history
…rder-customer-id-on-user-delete

When a WordPress user is deleted, turn any orders they have into Guest orders.
  • Loading branch information
mikejolley committed Oct 6, 2015
2 parents 1404f6a + aa86069 commit 5bc7de0
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions includes/wc-user-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -537,3 +537,14 @@ function wc_get_customer_order_count( $user_id ) {

return absint( $count );
}

/**
* Reset _customer_user on orders when a user is deleted.
* @param int $user_id
*/
function wc_reset_order_customer_id_on_deleted_user( $user_id ) {
global $wpdb;

$wpdb->update( $wpdb->postmeta, array( '_customer_user' => 0 ), array( '_customer_user' => $user_id ) );
}
add_action( 'deleted_user', 'wc_reset_customer_id_on_delete_user' );

0 comments on commit 5bc7de0

Please sign in to comment.