From ca2dfdd7c1d5ffcc2f84143f9f9aee17f113cd55 Mon Sep 17 00:00:00 2001 From: claudiosmweb Date: Thu, 24 Jul 2014 18:39:59 -0300 Subject: [PATCH] synchronized the trash and delete actions between orders and refunds #3164 --- includes/admin/class-wc-admin-post-types.php | 23 ++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/includes/admin/class-wc-admin-post-types.php b/includes/admin/class-wc-admin-post-types.php index 44f0a9ef804..5ca8b63be80 100644 --- a/includes/admin/class-wc-admin-post-types.php +++ b/includes/admin/class-wc-admin-post-types.php @@ -1734,6 +1734,13 @@ class WC_Admin_Post_Types { case 'product_variation' : wc_delete_product_transients( wp_get_post_parent_id( $id ) ); break; + case 'shop_order' : + $refunds = $wpdb->get_results( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type = 'shop_order_refund' AND post_parent = %d", $id ) ); + + foreach ( $refunds as $refund ) { + wp_delete_post( $refund->ID, true ); + } + break; } } } @@ -1746,6 +1753,8 @@ class WC_Admin_Post_Types { * @return void */ public function trash_post( $id ) { + global $wpdb; + if ( $id > 0 ) { $post_type = get_post_type( $id ); @@ -1760,6 +1769,12 @@ class WC_Admin_Post_Types { update_user_meta( $user_id, '_money_spent', '' ); } + $refunds = $wpdb->get_results( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type = 'shop_order_refund' AND post_parent = %d", $id ) ); + + foreach ( $refunds as $refund ) { + $wpdb->update( $wpdb->posts, array( 'post_status' => 'trash' ), array( 'ID' => $refund->ID ) ); + } + delete_transient( 'woocommerce_processing_order_count' ); } @@ -1774,6 +1789,8 @@ class WC_Admin_Post_Types { * @return void */ public function untrash_post( $id ) { + global $wpdb; + if ( $id > 0 ) { $post_type = get_post_type( $id ); @@ -1788,6 +1805,12 @@ class WC_Admin_Post_Types { update_user_meta( $user_id, '_money_spent', '' ); } + $refunds = $wpdb->get_results( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type = 'shop_order_refund' AND post_parent = %d", $id ) ); + + foreach ( $refunds as $refund ) { + $wpdb->update( $wpdb->posts, array( 'post_status' => 'wc-completed' ), array( 'ID' => $refund->ID ) ); + } + delete_transient( 'woocommerce_processing_order_count' ); }