From 41cb12c83076b664d5e9d69565ba2339390df75d Mon Sep 17 00:00:00 2001 From: Abdalsalaam Halawa Date: Thu, 20 Apr 2023 18:07:36 +0200 Subject: [PATCH] Decrease total sales after if order deleted --- plugins/woocommerce/includes/wc-order-functions.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugins/woocommerce/includes/wc-order-functions.php b/plugins/woocommerce/includes/wc-order-functions.php index 430fb0a43ad..a0c5c4030b3 100644 --- a/plugins/woocommerce/includes/wc-order-functions.php +++ b/plugins/woocommerce/includes/wc-order-functions.php @@ -879,6 +879,10 @@ function wc_update_total_sales_counts( $order_id ) { $recorded_sales = $order->get_data_store()->get_recorded_sales( $order ); $reflected_order = in_array( $order->get_status(), array( 'cancelled', 'refunded' ) ); + if ( ! $reflected_order && 'before_delete_post' === current_action() ) { + $reflected_order = true; + } + if ( $recorded_sales && ! $reflected_order ) { return; } @@ -915,6 +919,7 @@ add_action( 'woocommerce_order_status_on-hold', 'wc_update_total_sales_counts' ) add_action( 'woocommerce_order_status_completed_to_cancelled', 'wc_update_total_sales_counts' ); add_action( 'woocommerce_order_status_processing_to_cancelled', 'wc_update_total_sales_counts' ); add_action( 'woocommerce_order_status_on-hold_to_cancelled', 'wc_update_total_sales_counts' ); +add_action( 'before_delete_post', 'wc_update_total_sales_counts' ); /** * Update used coupon amount for each coupon within an order.