From c415d1554c8f513d2a5734732bc979834b9f683f Mon Sep 17 00:00:00 2001 From: Nicolae Vartolomei Date: Fri, 18 Sep 2015 16:39:24 +0300 Subject: [PATCH] Remove downloadable permissions on permanent order deletion --- includes/admin/class-wc-admin-post-types.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/includes/admin/class-wc-admin-post-types.php b/includes/admin/class-wc-admin-post-types.php index 8f397151ef1..a02013a928e 100644 --- a/includes/admin/class-wc-admin-post-types.php +++ b/includes/admin/class-wc-admin-post-types.php @@ -76,6 +76,7 @@ class WC_Admin_Post_Types { add_action( 'wp_trash_post', array( $this, 'trash_post' ) ); add_action( 'untrash_post', array( $this, 'untrash_post' ) ); add_action( 'before_delete_post', array( $this, 'delete_order_items' ) ); + add_action( 'before_delete_post', array( $this, 'delete_order_downloadable_permissions' ) ); // Edit post screens add_filter( 'enter_title_here', array( $this, 'enter_title_here' ), 1, 2 ); @@ -2029,6 +2030,24 @@ class WC_Admin_Post_Types { } } + /** + * Remove downloadable permissions on permanent order deletion + */ + public function delete_order_downloadable_permissions( $postid ) { + global $wpdb; + + if ( in_array( get_post_type( $postid ), wc_get_order_types() ) ) { + do_action( 'woocommerce_delete_order_downloadable_permissions', $postid ); + + $wpdb->query( $wpdb->prepare( " + DELETE FROM {$wpdb->prefix}woocommerce_downloadable_product_permissions + WHERE order_id = %d + ", $postid ) ); + + do_action( 'woocommerce_delete_order_downloadable_permissions', $postid ); + } + } + /** * Change title boxes in admin. * @param string $text