Skip to content

Instantly share code, notes, and snippets.

@mattmcgiv
Created April 12, 2016 14:09
Show Gist options
  • Select an option

  • Save mattmcgiv/26b7f0ce052892014ac9b79be068723e to your computer and use it in GitHub Desktop.

Select an option

Save mattmcgiv/26b7f0ce052892014ac9b79be068723e to your computer and use it in GitHub Desktop.
Get the total number of WooCommerce orders from WordPress
//gets the total number of WooCommerce orders from the WP database
function get_number_of_orders() {
global $wpdb;
//get number of orders from database as array
$number_of_orders_array_n = $wpdb->get_results(
"SELECT COUNT(*) FROM wp_posts WHERE post_type = 'shop_order'", ARRAY_N);
//convert number of orders array into a number
return $number_of_orders_array_n[0][0];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment