Top selling products in WooCommerce
Best-selling WooCommerce products by quantity, from the order line items.
WooCommerce · PostgreSQL
SELECT oi.order_item_name AS product,
SUM(CAST(qty.meta_value AS DECIMAL(10,2))) AS units_sold
FROM wp_woocommerce_order_items oi
JOIN wp_woocommerce_order_itemmeta qty
ON oi.order_item_id = qty.order_item_id AND qty.meta_key = '_qty'
WHERE oi.order_item_type = 'line_item'
GROUP BY oi.order_item_name
ORDER BY units_sold DESC
LIMIT 20;How it works
Reads the order line-item tables (classic, post-based WooCommerce). For stores on High-Performance Order Storage (HPOS), point the same logic at the wc_order_product_lookup table instead.
Run this on your own database
BeQuery mirrors your WooCommerce MySQL database to an isolated PostgreSQL copy, so you can run queries like this one without ever touching production.
Start free No credit card