From 841624a0b263c93d9c13939c139cb92fdb7819a0 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Wed, 21 Nov 2012 18:26:42 +0000 Subject: [PATCH] Ensure child_ids (transient) is cleared on delete. Closes #1786. --- admin/woocommerce-admin-functions.php | 6 ++++-- classes/class-wc-product.php | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/admin/woocommerce-admin-functions.php b/admin/woocommerce-admin-functions.php index 951812aa1b8..8de34b81133 100644 --- a/admin/woocommerce-admin-functions.php +++ b/admin/woocommerce-admin-functions.php @@ -83,7 +83,8 @@ function woocommerce_ms_protect_download_rewite_rules( $rewrite ) { * @return void */ function woocommerce_delete_post( $id ) { - + global $woocommerce; + if ( ! current_user_can( 'delete_posts' ) ) return; if ( $id > 0 ) : @@ -103,7 +104,8 @@ function woocommerce_delete_post( $id ) { endif; endif; - + + $woocommerce->clear_product_transients(); delete_transient( 'woocommerce_processing_order_count' ); } diff --git a/classes/class-wc-product.php b/classes/class-wc-product.php index 900f121dcf5..66193f4fc0d 100644 --- a/classes/class-wc-product.php +++ b/classes/class-wc-product.php @@ -393,7 +393,7 @@ class WC_Product { function exists() { global $wpdb; - return $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE ID = %d LIMIT 1;", $this->id ) ) > 0 ? true : false; + return ! empty( $this->post ) || $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE ID = %d LIMIT 1;", $this->id ) ) > 0 ? true : false; }