Merge pull request #9290 from woothemes/issue/9166-reset-order-customer-id-on-user-delete

When a WordPress user is deleted, turn any orders they have into Guest orders.
This commit is contained in:
Mike Jolley 2015-10-06 10:49:15 +01:00
commit 5bc7de0d91
1 changed files with 11 additions and 0 deletions

View File

@ -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' );