wc_delete_shop_order_transients

Clear all transients cache for order data.

Description

wc_delete_shop_order_transients( (int) $order = 0 ); 

Parameters (1)

0. $order — Optional. (int)
The order.

Usage

  1. if ( !function_exists( 'wc_delete_shop_order_transients' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-order-functions.php'; 
  3.  
  4. // The order. 
  5. $order = -1; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wc_delete_shop_order_transients($order); 
  9.  

Defined (1)

The function is defined in the following location(s).

/includes/wc-order-functions.php  
  1. function wc_delete_shop_order_transients( $order = 0 ) { 
  2. if ( is_numeric( $order ) ) { 
  3. $order = wc_get_order( $order ); 
  4. $reports = WC_Admin_Reports::get_reports(); 
  5. $transients_to_clear = array( 
  6. wc_admin_report 
  7. ); 
  8.  
  9. foreach ( $reports as $report_group ) { 
  10. foreach ( $report_group['reports'] as $report_key => $report ) { 
  11. $transients_to_clear[] = 'wc_report_' . $report_key; 
  12.  
  13. foreach ( $transients_to_clear as $transient ) { 
  14. delete_transient( $transient ); 
  15.  
  16. // Clear money spent for user associated with order 
  17. if ( is_a( $order, 'WC_Order' ) ) { 
  18. $order_id = $order->get_id(); 
  19. delete_user_meta( $order->get_customer_id(), '_money_spent' ); 
  20. delete_user_meta( $order->get_customer_id(), '_order_count' ); 
  21. } else { 
  22. $order_id = 0; 
  23.  
  24. // Increments the transient version to invalidate cache 
  25. WC_Cache_Helper::get_transient_version( 'orders', true ); 
  26.  
  27. // Do the same for regular cache 
  28. WC_Cache_Helper::incr_cache_prefix( 'orders' ); 
  29.  
  30. do_action( 'woocommerce_delete_shop_order_transients', $order_id );