Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Monthly Sales Custom Shortcode
- */
- add_shortcode( 'display_monthly_sales', 'print_monthly_sales_frontend' );
- function print_monthly_sales_frontend() {
- global $woocommerce, $wpdb, $product;
- include_once($woocommerce->plugin_path() . '/includes/admin/reports/class-wc-admin-report.php');
- // WooCommerce Admin Report
- $wc_report = new WC_Admin_Report();
- // Set date parameters for the current month
- $start_date = strtotime(date('Y-m', current_time('timestamp')) . '-01 midnight');
- $end_date = strtotime('+1month', $start_date) - 86400;
- $wc_report->start_date = $start_date;
- $wc_report->end_date = $end_date;
- // Avoid max join size error
- $wpdb->query('SET SQL_BIG_SELECTS=1');
- $last_month = (array) $wc_report->get_order_report_data(
- array(
- 'data' => array(
- '_order_total' => array(
- 'type' => 'meta',
- 'function' => 'SUM',
- 'name' => 'total_sales',
- ),
- ),
- 'group_by' => $wc_report->group_by_query,
- 'order_by' => 'post_date ASC',
- 'query_type' => 'get_results',
- 'filter_range' => 'month',
- 'order_types' => wc_get_order_types( 'sales-reports' ),
- 'order_status' => array( 'completed', 'processing', 'on-hold', 'refunded' ),
- )
- );
- ?>
- <div class="total-sales">
- <h1><?php echo get_woocommerce_currency_symbol() . intval($last_month[0]->total_sales); ?></h1>
- <p>Last 30 days in sales</p>
- </div>
- <?php
- }
Add Comment
Please, Sign In to add comment