Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- add_action( 'woocommerce_after_register_post_type', 'wan_get_post' );
- function wan_get_post() {
- $day = date('w');
- $week_start = date('Y-m-d', strtotime('-'.$day.' days'));
- $week_end = date('Y-m-d', strtotime('+'.(6-$day).' days'));
- $wtd_orders = wc_get_orders(
- [
- 'date_paid' => $week_start . '...' . $week_end,
- ]
- );
- $mtd_orders = wc_get_orders(
- [
- 'date_paid' => date('Y-m-01') . '...' . date('Y-m-t'),
- ]
- );
- $ytd_orders = wc_get_orders(
- [
- 'date_paid' => date('Y-01-01') . '...' . date('Y-m-t'),
- ]
- );
- $wtd_total = 0;
- $mtd_total = 0;
- $ytd_total = 0;
- foreach( $wtd_orders as $order ) {
- $wtd_total+= round( $order->get_total() * 100);
- }
- foreach( $mtd_orders as $order ) {
- $mtd_total+= round( $order->get_total() * 100);
- }
- foreach( $ytd_orders as $order ) {
- $ytd_total+= round( $order->get_total() * 100);
- }
- echo 'Total Weekly Sales: RM ' . number_format($wtd_total/ 100, 2) . '<br>';
- echo 'Total Monthly Sales: RM ' . number_format($mtd_total/ 100, 2) . '<br>';
- echo 'Total Yearly Sales: RM ' . number_format($ytd_total/ 100, 2) . '<br>';
- exit;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement