Guest User

Untitled

a guest
Jun 13th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. /**
  2. * Monthly Sales Custom Shortcode
  3. */
  4. add_shortcode( 'display_monthly_sales', 'print_monthly_sales_frontend' );
  5.  
  6. function print_monthly_sales_frontend() {
  7. global $woocommerce, $wpdb, $product;
  8. include_once($woocommerce->plugin_path() . '/includes/admin/reports/class-wc-admin-report.php');
  9.  
  10. // WooCommerce Admin Report
  11. $wc_report = new WC_Admin_Report();
  12.  
  13. // Set date parameters for the current month
  14. $start_date = strtotime(date('Y-m', current_time('timestamp')) . '-01 midnight');
  15. $end_date = strtotime('+1month', $start_date) - 86400;
  16. $wc_report->start_date = $start_date;
  17. $wc_report->end_date = $end_date;
  18.  
  19. // Avoid max join size error
  20. $wpdb->query('SET SQL_BIG_SELECTS=1');
  21.  
  22. $last_month = (array) $wc_report->get_order_report_data(
  23. array(
  24. 'data' => array(
  25. '_order_total' => array(
  26. 'type' => 'meta',
  27. 'function' => 'SUM',
  28. 'name' => 'total_sales',
  29. ),
  30. ),
  31. 'group_by' => $wc_report->group_by_query,
  32. 'order_by' => 'post_date ASC',
  33. 'query_type' => 'get_results',
  34. 'filter_range' => 'month',
  35. 'order_types' => wc_get_order_types( 'sales-reports' ),
  36. 'order_status' => array( 'completed', 'processing', 'on-hold', 'refunded' ),
  37. )
  38. );
  39.  
  40. ?>
  41. <div class="total-sales">
  42. <h1><?php echo get_woocommerce_currency_symbol() . intval($last_month[0]->total_sales); ?></h1>
  43. <p>Last 30 days in sales</p>
  44. </div>
  45. <?php
  46. }
Add Comment
Please, Sign In to add comment