I am completely at a loss on how to get some 'relatively' simple data from my woocommerce orders.
What I need is a query that allows me to simply plug in a category as well as a tag and return the total sales (as income [$]) so that I can do some simple math with the results and display the amount.
I am trying to have a storefront on my studios website that is broken down into categories by project "Webcomic", "Game", Etc. and then filter the sales of ANY of the product sales within the category by the tag "contribution" or "sales".
The purpose for this is to have a very rudimentary metric display on a project page which breaks down what I've invested in the project in time and money, and what I've earned from it in patronage and merch sales.
The idea being that I go:
If not tags and categories, how would I go about giving my products custom fields that I'd be able to query through the orders?
Any help in this regard would be immensely helpful.
Added through further study:
This question asks WHERE the order data is being stored.
How would I go about querying the different chunks of data to trace a line to all the chunks I need?
Query shop_orders > Loop through Orders > push orders who's order_item has the right category and tags to an array
Is my initial thought. Would there be a more efficient way to do this?
I copied the function: public function awts_get_total_sales_per_product($product_id ='')
from line 92 into my custom shortcodes file.
I then made my own query:
$args = array(
'numberposts' => -1,
'post_type' => 'product',
'product_cat' => $shopSlug,
'product_tag' => 'contribution', //contribution in one query, merch in the other.
'orderby' => 'date',
'order' => 'dsc');
Then just did a foreach loop to sum all of the results:
$query = get_posts( $args );
foreach ( $query as $post ) : setup_postdata( $post );
$var = awts_get_total_sales_per_product($post->ID);
$contributed += $var->{_line_total};
endforeach;
I would like to thank the people who put the work into the Woo-Total-Sales plugin, I'm actually going to continue using it on the site. I was hoping I didn't have to hack apart a well made plugin to get what I needed but it's been 3 days and I really need to move on with my development.