Skip to content
Advertisement

Count number of orders for a variation in Woocommerce

I have figured a way to do this, but I am finding my queries are taking way too long, and the more orders in Woocmmerce, and the more variations we add, the longer the query takes…

I would hope there is a way in WC or WP to query just variation ids of an order, but alas, I havent found it yet. I need to do sales report by variation.

Advertisement

Answer

You can get the count of orders from specific orders status from a variation ID with this very light SQL query embedded in the following function:

Code goes in function.php file of your active child theme (or active theme). Tested and Works.

USAGE EXAMPLE (Displaying orders count for variation ID 41):

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement