So i want to calculate the total sale amount, excluding tax, for my website. However, i have a enormous load of orders on the website. Making it crash the page because it can't handle the calculation. Is there a better way to calculate / retrieve this from WooCommerce?
function calculateTotalSales(){
$orders = get_posts( array(
'numberposts' => - 1,
'post_type' => array( 'shop_order' ),
'post_status' => array( 'wc-completed', 'wc-processing', 'wc-pending' )
) );
$total = 0;
foreach ( $orders as $customer_order ) {
$order = wc_get_order( $customer_order );
$total += $order->get_total() - $order->get_total_tax();
}
update_option('totalSales', $totalSales);
return $totalSales;
}