wc_update_total_sales_counts

Update total sales amount for each product within a paid order.

Description

wc_update_total_sales_counts( (int) $order_id ); 

Parameters (1)

0. $order_id (int)
The order id.

Usage

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

Defined (1)

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

/includes/wc-order-functions.php  
  1. function wc_update_total_sales_counts( $order_id ) { 
  2. $order = wc_get_order( $order_id ); 
  3.  
  4. if ( ! $order || $order->get_data_store()->get_recorded_sales( $order ) ) { 
  5. return; 
  6.  
  7. if ( sizeof( $order->get_items() ) > 0 ) { 
  8. foreach ( $order->get_items() as $item ) { 
  9. if ( $product_id = $item->get_product_id() ) { 
  10. $data_store = WC_Data_Store::load( 'product' ); 
  11. $data_store->update_product_sales( $product_id, absint( $item['qty'] ), 'increase' ); 
  12.  
  13. $order->get_data_store()->set_recorded_sales( $order, true ); 
  14.  
  15. /** 
  16. * Called when sales for an order are recorded 
  17. * @param int $order_id order id 
  18. */ 
  19. do_action( 'woocommerce_recorded_sales', $order_id );