Revert "Set post_author to 0 on all orders that belong to a deleted customer"

This reverts commit f725dc17af.
This commit is contained in:
Rodrigo Primo 2018-10-29 11:16:07 -03:00
parent f109008e0d
commit a2c18145fc
1 changed files with 1 additions and 16 deletions

View File

@ -545,7 +545,7 @@ function wc_get_customer_order_count( $user_id ) {
}
/**
* Reset customer ID on orders when a user is deleted.
* Reset _customer_user on orders when a user is deleted.
*
* @param int $user_id User ID.
*/
@ -558,21 +558,6 @@ function wc_reset_order_customer_id_on_deleted_user( $user_id ) {
'meta_value' => $user_id,
)
); // WPCS: slow query ok.
$post_types = (array) apply_filters( 'woocommerce_reset_order_customer_id_post_types', array( 'shop_order' ) );
$post_types_placeholders = implode( ', ', array_fill( 0, count( $post_types ), '%s' ) );
// Since WC 3.5, the customer ID is stored both in the _customer_user postmeta and in the post_author field.
// In future versions of WC, the plan is to use only post_author and stop using _customer_user, but for now
// we have to update both places.
$wpdb->query(
// phpcs:disable WordPress.WP.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
$wpdb->prepare(
"UPDATE {$wpdb->posts} SET `post_author` = 0 WHERE post_type IN ({$post_types_placeholders}) AND post_author = {$user_id}",
$post_types
)
// phpcs:enable
);
}
add_action( 'deleted_user', 'wc_reset_order_customer_id_on_deleted_user' );