From 0c30999a67974d96e0f3182641252db61f9986c1 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Mon, 8 Feb 2016 12:26:46 +0000 Subject: [PATCH] When orders update, invalidate money spent user meta. Closes #9562 --- includes/admin/class-wc-admin-post-types.php | 8 ++++---- includes/wc-order-functions.php | 6 ++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/includes/admin/class-wc-admin-post-types.php b/includes/admin/class-wc-admin-post-types.php index f6078e13957..66f062fe77d 100644 --- a/includes/admin/class-wc-admin-post-types.php +++ b/includes/admin/class-wc-admin-post-types.php @@ -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 ) ); diff --git a/includes/wc-order-functions.php b/includes/wc-order-functions.php index 41d2a819121..6aa7d97b65d 100644 --- a/includes/wc-order-functions.php +++ b/includes/wc-order-functions.php @@ -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 );