Skip to content

Commit

Permalink
Merge pull request #38 from upsellpl/hotfix/PB-792
Browse files Browse the repository at this point in the history
PB-792 Naprawić liczbę zamówień po usunięciu jednej z transakcji
  • Loading branch information
mbwawpl authored Nov 30, 2023
2 parents cdc615f + e006ef5 commit 45bdf38
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
13 changes: 9 additions & 4 deletions includes/admin/payments/actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
}
}

}
Expand Down
2 changes: 1 addition & 1 deletion includes/class-edd-customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
8 changes: 0 additions & 8 deletions includes/payments/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down

0 comments on commit 45bdf38

Please sign in to comment.