From 41183d166308f4e7b26d9ba818355d33165578ad Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Wed, 26 Feb 2014 15:43:19 +0000 Subject: [PATCH] wc_delete_shop_order_transients functions and trigger when order status updates. Closes #4875 --- .../class-wc-meta-box-order-data.php | 4 +--- includes/class-wc-order.php | 2 +- includes/wc-order-functions.php | 24 +++++++++++++++++++ 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/includes/admin/post-types/meta-boxes/class-wc-meta-box-order-data.php b/includes/admin/post-types/meta-boxes/class-wc-meta-box-order-data.php index ef0d1f9abe3..aed6b8cdc25 100644 --- a/includes/admin/post-types/meta-boxes/class-wc-meta-box-order-data.php +++ b/includes/admin/post-types/meta-boxes/class-wc-meta-box-order-data.php @@ -395,8 +395,6 @@ class WC_Meta_Box_Order_Data { // Order status $order->update_status( $_POST['order_status'] ); - delete_transient( 'woocommerce_processing_order_count' ); - - $wpdb->query( "DELETE FROM `$wpdb->options` WHERE `option_name` LIKE ('_transient_wc_report_%') OR `option_name` LIKE ('_transient_timeout_wc_report_%')" ); + wc_delete_shop_order_transients( $post_id ); } } \ No newline at end of file diff --git a/includes/class-wc-order.php b/includes/class-wc-order.php index f562676d5fe..817e8476d98 100644 --- a/includes/class-wc-order.php +++ b/includes/class-wc-order.php @@ -1314,7 +1314,7 @@ class WC_Order { } - delete_transient( 'woocommerce_processing_order_count' ); + wc_delete_shop_order_transients( $this->id ); } diff --git a/includes/wc-order-functions.php b/includes/wc-order-functions.php index 7317dfeae61..2d7db30caa3 100644 --- a/includes/wc-order-functions.php +++ b/includes/wc-order-functions.php @@ -325,3 +325,27 @@ function wc_processing_order_count() { return $order_count; } +/** + * Clear all transients cache for order data. + * + * @param int $post_id (default: 0) + */ +function wc_delete_shop_order_transients( $post_id = 0 ) { + global $wpdb; + + $post_id = absint( $post_id ); + + // Clear core transients + $transients_to_clear = array( + 'woocommerce_processing_order_count' + ); + + foreach( $transients_to_clear as $transient ) { + delete_transient( $transient ); + } + + // Clear transients for which we don't have the name + $wpdb->query( "DELETE FROM `$wpdb->options` WHERE `option_name` LIKE ('_transient_wc_report_%') OR `option_name` LIKE ('_transient_timeout_wc_report_%')" ); + + do_action( 'woocommerce_delete_shop_order_transients', $post_id ); +}