From ab662882d34bae370264a3defd90787815cb9a06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Bogda=C5=84ski?= Date: Wed, 29 Nov 2023 18:52:35 +0100 Subject: [PATCH 1/2] =?UTF-8?q?PB-792=20Naprawi=C4=87=20liczb=C4=99=20zam?= =?UTF-8?q?=C3=B3wie=C5=84=20po=20usuni=C4=99ciu=20jednej=20z=20transakcji?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- includes/admin/payments/actions.php | 13 +++++++++---- includes/class-edd-customer.php | 4 +--- includes/payments/functions.php | 8 -------- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/includes/admin/payments/actions.php b/includes/admin/payments/actions.php index 454c6bb9429..39104e93c71 100644 --- a/includes/admin/payments/actions.php +++ b/includes/admin/payments/actions.php @@ -214,10 +214,10 @@ function edd_update_payment_details( $data ) { $customer->attach_payment( $payment_id, false ); // If purchase was completed and not ever refunded, adjust stats of customers - if( 'revoked' == $status || 'publish' == $status ) { + if( 'publish' == $status ) { $previous_customer->decrease_purchase_count(); - $previous_customer->decrease_value( $new_total ); + $previous_customer->decrease_value( $curr_total ); $customer->increase_purchase_count(); $customer->increase_value( $new_total ); @@ -250,18 +250,23 @@ function edd_update_payment_details( $data ) { $payment->status = $status; // Adjust total store earnings if the payment total has been changed - if ( $new_total !== $curr_total && ( 'publish' == $status || 'revoked' == $status ) ) { + if ( $new_total !== $curr_total && ( 'publish' == $status ) ) { if ( $new_total > $curr_total ) { // Increase if our new total is higher $difference = $new_total - $curr_total; edd_increase_total_earnings( $difference ); + if ( !$customer_changed ) { + $customer->increase_value( $difference ); + } } elseif ( $curr_total > $new_total ) { // Decrease if our new total is lower $difference = $curr_total - $new_total; edd_decrease_total_earnings( $difference ); - + if ( !$customer_changed ) { + $customer->decrease_value( $difference ); + } } } diff --git a/includes/class-edd-customer.php b/includes/class-edd-customer.php index 889c6ee6d8d..24fa0d575fb 100644 --- a/includes/class-edd-customer.php +++ b/includes/class-edd-customer.php @@ -347,7 +347,7 @@ public function remove_payment( $payment_id = 0, $update_stats = true ) { $payment = new EDD_Payment( $payment_id ); - if ( 'publish' !== $payment->status && 'revoked' !== $payment->status ) { + if ( 'publish' !== $payment->status ) { $update_stats = false; } @@ -429,7 +429,6 @@ public function increase_purchase_count( $count = 1 ) { * @return mixed If successful, the new count, otherwise false */ public function decrease_purchase_count( $count = 1 ) { - // Make sure it's numeric and not negative if ( ! is_numeric( $count ) || $count != absint( $count ) ) { return false; @@ -448,7 +447,6 @@ public function decrease_purchase_count( $count = 1 ) { } do_action( 'edd_customer_post_decrease_purchase_count', $this->purchase_count, $count, $this->id ); - return $this->purchase_count; } diff --git a/includes/payments/functions.php b/includes/payments/functions.php index 0b1f10b9483..46b3c074217 100644 --- a/includes/payments/functions.php +++ b/includes/payments/functions.php @@ -279,14 +279,6 @@ function edd_delete_purchase( $payment_id = 0, $update_customer = true, $delete_ edd_decrease_total_earnings( $amount ); // Clear the This Month earnings (this_monththis_month is NOT a typo) delete_transient( md5( 'edd_earnings_this_monththis_month' ) ); - - if( $customer->id && $update_customer ) { - - // Decrement the stats for the customer - $customer->decrease_purchase_count(); - $customer->decrease_value( $amount ); - - } } if( $customer->id && $update_customer ) { From e006ef52e3614d052c3003f11c4a82cfbc9785e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Bogda=C5=84ski?= Date: Thu, 30 Nov 2023 12:52:58 +0100 Subject: [PATCH 2/2] =?UTF-8?q?PB-792=20Naprawi=C4=87=20liczb=C4=99=20zam?= =?UTF-8?q?=C3=B3wie=C5=84=20po=20usuni=C4=99ciu=20jednej=20z=20transakcji?= =?UTF-8?q?=20-=20poprawka=20formatowania?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- includes/class-edd-customer.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/includes/class-edd-customer.php b/includes/class-edd-customer.php index 24fa0d575fb..2bdc627a384 100644 --- a/includes/class-edd-customer.php +++ b/includes/class-edd-customer.php @@ -429,6 +429,7 @@ public function increase_purchase_count( $count = 1 ) { * @return mixed If successful, the new count, otherwise false */ public function decrease_purchase_count( $count = 1 ) { + // Make sure it's numeric and not negative if ( ! is_numeric( $count ) || $count != absint( $count ) ) { return false; @@ -447,6 +448,7 @@ public function decrease_purchase_count( $count = 1 ) { } do_action( 'edd_customer_post_decrease_purchase_count', $this->purchase_count, $count, $this->id ); + return $this->purchase_count; }