I'm looking for a code snippet to get total sales of each product for today, so I can use it in my theme functions.php file.
Output should be like this (Total Sales Per Item):
Product xxx = 25 orders
Product yyy = 18 orders
Product zzz = 8 orders
I'm looking for a code snippet to get total sales of each product for today, so I can use it in my theme functions.php file.
Output should be like this (Total Sales Per Item):
Product xxx = 25 orders
Product yyy = 18 orders
Product zzz = 8 orders
This can be done with the following very light SQL query and a foreach loop.
That will give you the list of products (and product variations, but not parent variable products) of orders count by product for the past 24 hours:
Tested and works.
If you want to get instead the total based on the "today" date, you will replace in the code this line:
by this line:
Related similar answers: