Devin Walker is a San Diego based entrepreneur, developer and designer.

WooCommerce: How to Get Total Sales and Orders of All Products

Posted on Nov 5, 2015 in Coding | 24 Comments

Woocommerce Total SalesUPDATE 11/5/2015: A lot has changed in WooCommerce since this article was published so I have updated a few of the functions below so they are up to date with the latest version 🙂 – if you’re looking for how to deal with order data, check out this article.


Perhaps you have to display some stats on the frontend and need the total sales number to use with some math. Here is how I found out how to tap into the data provided by WooCommerce’s admin reporting functionality.

Data Points:

  • Total Sales
  • Total Orders
  • Total of All Shipping Costs
  • Total of All Discounts Used
  • Total of All Items Ordered
  • Total Sales Per Item

WooCommerce comes with built-in reporting in the WordPress admin dashboard. The admin reporting code can be found in woocommerce/admin/woocommerce-admin-reports.php. If you have been selling on WooCommerce for awhile, you should be familiar with the dashboard reporting screen:


How to Get Total Sales Number

The following code will query your WordPress database and retreive the total sales of your site. Be sure to update the function name so it’s unique.

Once this is in a custom functionality plugin, or if it has to be, your theme’s functions.php file then you are ready to use it. Just echo it out within your template files or wherever you need it to show.

Get Total of All Shipping Costs

Total of All Discounts Used

Total of All Items Ordered

Total Sales Per Item

The following code will return an array of objects containing product ids and their corresponding total sales.

.. then using the array returned above you could loop through the results and do basic math to get your totals:

Know of a better way to do this? Please share! Use the comments below to describe how you grab the total sales, orders and additional reporting data from WooCommerce.

Please keep in mind I have not done any security testing on this code but I believe it’s secure enough.