synchronized the trash and delete actions between orders and refunds #3164

This commit is contained in:
claudiosmweb 2014-07-24 18:39:59 -03:00
parent e634efa958
commit ca2dfdd7c1
1 changed files with 23 additions and 0 deletions

View File

@ -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' );
}