When orders update, invalidate money spent user meta.

Closes #9562
This commit is contained in:
Mike Jolley 2016-02-08 12:26:46 +00:00
parent 564802a9c4
commit 0c30999a67
2 changed files with 10 additions and 4 deletions

View File

@ -1979,8 +1979,8 @@ class WC_Admin_Post_Types {
$user_id = get_post_meta( $id, '_customer_user', true );
if ( $user_id > 0 ) {
update_user_meta( $user_id, '_order_count', '' );
update_user_meta( $user_id, '_money_spent', '' );
delete_user_meta( $user_id, '_money_spent' );
delete_user_meta( $user_id, '_order_count' );
}
$refunds = $wpdb->get_results( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type = 'shop_order_refund' AND post_parent = %d", $id ) );
@ -2014,8 +2014,8 @@ class WC_Admin_Post_Types {
$user_id = get_post_meta( $id, '_customer_user', true );
if ( $user_id > 0 ) {
update_user_meta( $user_id, '_order_count', '' );
update_user_meta( $user_id, '_money_spent', '' );
delete_user_meta( $user_id, '_money_spent' );
delete_user_meta( $user_id, '_order_count' );
}
$refunds = $wpdb->get_results( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type = 'shop_order_refund' AND post_parent = %d", $id ) );

View File

@ -579,6 +579,12 @@ function wc_delete_shop_order_transients( $post_id = 0 ) {
delete_transient( $transient );
}
// Clear money spent for user associated with order
if ( $post_id && ( $user_id = get_post_meta( $post_id, '_customer_user', true ) ) ) {
delete_user_meta( $user_id, '_money_spent' );
delete_user_meta( $user_id, '_order_count' );
}
// Increments the transient version to invalidate cache
WC_Cache_Helper::get_transient_version( 'orders', true );