I try to count how many products were sold each week from Friday to Friday.
I try to use meta_key total_sales, but it shows the total amount of products sold.
I want to create a report that shows what products and how many were sold in one week.
I wanted to specify the name of the product and the number of units sold for each example:
Butter 20 sold
Bread B 20 sold
e.t.c
$sql_total_sold=("SELECT p.post_title as product, 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 LIKE 'total_sales') WHERE pm.meta_value >0 AND p.post_type LIKE 'product' AND p.post_status LIKE 'publish'");
$results = $wpdb->get_results($sql_total_sold);
$counter=0;
foreach($results as $result){
$counter++;
echo $counter.' Product name : '.$result->product.'quantity'. $result->total_sales .'</br>';
}
2
Answers
Display last week total sales ( number of products sold )
Try to change your query to something like:
But I am not sure if it is going to work correct with summer time.