For Woocommerce, I wrote code below, trying to get orders total purchases amount for today:
function order_total_woo_fahad(){
// Get orders from people named John that were paid in the year 2016.
$orders = wc_get_orders( array(
'date_paid' => '2018-07-03'
) );
$total_of_all=0;
for($i=0;$orders[i];$i++)
$total_of_all= $orders[i]->get_total();
return $total_of_all;
}
But it returns null.
What I am doing wrong? How can I get orders total purchases amount for the day?
The best and effective way to get that is to use the following very light SQL query, that will get the sum of all order totals in the last 24 hours for "processing" and "completed" orders statuses:
Code goes in function.php file of your active child theme (or active theme). Tested and works.
USAGE Example - Display the daily total purchased formatted amount:
If you want to get instead the total based on the "today" date, you will replace in the code this line:
by this line: