Skip to content

Instantly share code, notes, and snippets.

@8lane
Created July 14, 2014 10:28
Show Gist options
  • Select an option

  • Save 8lane/d0222d81362f4ea1fa2d to your computer and use it in GitHub Desktop.

Select an option

Save 8lane/d0222d81362f4ea1fa2d to your computer and use it in GitHub Desktop.
Get total amount of customers in WooCommerce
function totalCustomers() {
global $wpdb;
$result = $wpdb->get_row("
SELECT SUM(pm.meta_value) AS total_sales
FROM $wpdb->posts AS p
LEFT JOIN $wpdb->postmeta AS pm ON (p.ID = pm.post_id AND pm.meta_key = 'total_sales')
WHERE p.post_type = 'product'
");
return $result->total_sales;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment