Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- global $wpdb;
- $sql = "";
- $sql .= "SELECT SUM(wc_postmeta1.meta_value) AS 'Total'
- ,wc_postmeta2.meta_value AS 'BillingEmail'
- ,CONCAT(wc_postmeta3.meta_value, ' ',wc_postmeta5.meta_value) AS BillingName
- ,Count(wc_postmeta2.meta_value) AS 'OrderCount' FROM ";
- $sql .= "{$wpdb->prefix}posts as wc_posts
- LEFT JOIN {$wpdb->prefix}postmeta as wc_postmeta1 ON wc_postmeta1.post_id=wc_posts.ID
- LEFT JOIN {$wpdb->prefix}postmeta as wc_postmeta2 ON wc_postmeta2.post_id=wc_posts.ID
- LEFT JOIN {$wpdb->prefix}postmeta as wc_postmeta3 ON wc_postmeta3.post_id=wc_posts.ID
- LEFT JOIN {$wpdb->prefix}postmeta as wc_postmeta5 ON wc_postmeta5.post_id=wc_posts.ID";
- $sql .= " WHERE wc_posts.post_type='shop_order'
- AND wc_postmeta1.meta_key='_order_total'
- AND wc_postmeta2.meta_key='_billing_email'
- AND wc_postmeta3.meta_key='_billing_first_name'
- AND wc_postmeta5.meta_key='_billing_last_name'";
- $sql .= " AND wc_posts.post_status IN ('wc-completed','wc-processing')";
- $sql .= " AND MONTH(wc_posts.post_date) = MONTH(CURRENT_DATE())AND YEAR(wc_posts.post_date) = YEAR(CURRENT_DATE())";
- $sql .= " GROUP BY wc_postmeta2.meta_value";
- $sql .= " Order By Total DESC";
- $sql .= " LIMIT 0,10";
- $result = $wpdb->get_results($sql, OBJECT);
- echo"<table>";
- echo "<tr>";
- echo "<th>No</th>";
- echo "<th>Nama</th>";
- echo "<th>Order</th>";
- echo "<th>Belian (RM)</th>";
- echo "</tr>";
- $i=1;
- foreach ($result as $customer) {
- echo "<tr>";
- echo "<td>$i</td>";
- echo "<td>$customer->BillingName</td>";
- echo "<td>$customer->OrderCount</td>";
- echo "<td>$customer->Total</td>";
- echo "</tr>";
- $i++;
- }
- echo"</table>";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement