From 3db3f3796eb28fb79983f605a5a70d61ca114c6d Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Mon, 9 May 2016 10:01:12 +0100 Subject: [PATCH] Clear item meta cache when adding new meta --- includes/wc-order-functions.php | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/includes/wc-order-functions.php b/includes/wc-order-functions.php index 1f9a9eb0107..058abbc234f 100644 --- a/includes/wc-order-functions.php +++ b/includes/wc-order-functions.php @@ -604,7 +604,12 @@ function wc_delete_order_item( $item_id ) { * @return bool */ function wc_update_order_item_meta( $item_id, $meta_key, $meta_value, $prev_value = '' ) { - return update_metadata( 'order_item', $item_id, $meta_key, $meta_value, $prev_value ); + if ( update_metadata( 'order_item', $item_id, $meta_key, $meta_value, $prev_value ) ) { + $cache_key = WC_Cache_Helper::get_cache_prefix( 'orders' ) . 'item_meta_array_' . $item_id; + wp_cache_delete( $cache_key, 'orders' ); + return true; + } + return false; } /** @@ -618,7 +623,12 @@ function wc_update_order_item_meta( $item_id, $meta_key, $meta_value, $prev_valu * @return bool */ function wc_add_order_item_meta( $item_id, $meta_key, $meta_value, $unique = false ) { - return add_metadata( 'order_item', $item_id, $meta_key, $meta_value, $unique ); + if ( add_metadata( 'order_item', $item_id, $meta_key, $meta_value, $unique ) ) { + $cache_key = WC_Cache_Helper::get_cache_prefix( 'orders' ) . 'item_meta_array_' . $item_id; + wp_cache_delete( $cache_key, 'orders' ); + return true; + } + return false; } /** @@ -632,7 +642,12 @@ function wc_add_order_item_meta( $item_id, $meta_key, $meta_value, $unique = fal * @return bool */ function wc_delete_order_item_meta( $item_id, $meta_key, $meta_value = '', $delete_all = false ) { - return delete_metadata( 'order_item', $item_id, $meta_key, $meta_value, $delete_all ); + if ( delete_metadata( 'order_item', $item_id, $meta_key, $meta_value, $delete_all ) ) { + $cache_key = WC_Cache_Helper::get_cache_prefix( 'orders' ) . 'item_meta_array_' . $item_id; + wp_cache_delete( $cache_key, 'orders' ); + return true; + } + return false; } /**