array( 'title' => __( 'Sales', 'woocommerce' ), 'charts' => array( array( 'title' => __( 'Overview', 'woocommerce' ), 'description' => '', 'hide_title' => true, 'function' => 'woocommerce_sales_overview' ), array( 'title' => __( 'Sales by day', 'woocommerce' ), 'description' => '', 'function' => 'woocommerce_daily_sales' ), array( 'title' => __( 'Sales by month', 'woocommerce' ), 'description' => '', 'function' => 'woocommerce_monthly_sales' ), array( 'title' => __( 'Taxes by month', 'woocommerce' ), 'description' => '', 'function' => 'woocommerce_monthly_taxes' ), array( 'title' => __( 'Product Sales', 'woocommerce' ), 'description' => '', 'function' => 'woocommerce_product_sales' ), array( 'title' => __( 'Top sellers', 'woocommerce' ), 'description' => '', 'function' => 'woocommerce_top_sellers' ), array( 'title' => __( 'Top earners', 'woocommerce' ), 'description' => '', 'function' => 'woocommerce_top_earners' ), array( 'title' => __( 'Sales by category', 'woocommerce' ), 'description' => '', 'function' => 'woocommerce_category_sales' ), array( 'title' => __( 'Sales by coupon', 'woocommerce' ), 'description' => '', 'function' => 'woocommerce_coupon_sales' ) ) ), 'customers' => array( 'title' => __( 'Customers', 'woocommerce' ), 'charts' => array( array( 'title' => __( 'Overview', 'woocommerce' ), 'description' => '', 'hide_title' => true, 'function' => 'woocommerce_customer_overview' ), ) ), 'stock' => array( 'title' => __( 'Stock', 'woocommerce' ), 'charts' => array( array( 'title' => __( 'Overview', 'woocommerce' ), 'description' => '', 'hide_title' => true, 'function' => 'woocommerce_stock_overview' ), ) ) ) ); $first_tab = array_keys($charts); $first_chart = array_keys($charts[$first_tab[0]]['charts']); $current_tab = isset( $_GET['tab'] ) ? sanitize_title( urldecode( $_GET['tab'] ) ) : $first_tab[0]; $current_chart = isset( $_GET['chart'] ) ? absint( urldecode( $_GET['chart'] ) ) : $first_chart[0]; ?>

1 ) { ?>
' . $chart['title'] . ''; if ( $chart['description'] ) echo '

' . $chart['description'] . '

'; $func = $chart['function']; if ( $func && function_exists( $func ) ) $func(); } ?>
function weekendAreas(axes) { var markings = []; var d = new Date(axes.xaxis.min); // go to the first Saturday d.setUTCDate(d.getUTCDate() - ((d.getUTCDay() + 1) % 7)) d.setUTCSeconds(0); d.setUTCMinutes(0); d.setUTCHours(0); var i = d.getTime(); do { markings.push({ xaxis: { from: i, to: i + 2 * 24 * 60 * 60 * 1000 } }); i += 7 * 24 * 60 * 60 * 1000; } while (i < axes.xaxis.max); return markings; } function showTooltip(x, y, contents) { jQuery('
' + contents + '
').css( { position: 'absolute', display: 'none', top: y + 5, left: x + 5, padding: '5px 10px', border: '3px solid #3da5d5', background: '#288ab7' }).appendTo("body").fadeIn(200); } var previousPoint = null; jQuery("#placeholder").bind("plothover", function (event, pos, item) { if (item) { if (previousPoint != item.dataIndex) { previousPoint = item.dataIndex; jQuery("#tooltip").remove(); if (item.series.label=="") { var y = item.datapoint[1].toFixed(2); showTooltip(item.pageX, item.pageY, item.series.label + " - " + "" + y); } else if (item.series.label=="") { var y = item.datapoint[1]; showTooltip(item.pageX, item.pageY, item.series.label + " - " + y); } else { var y = item.datapoint[1]; showTooltip(item.pageX, item.pageY, y); } } } else { jQuery("#tooltip").remove(); previousPoint = null; } }); var dates = jQuery( "#from, #to" ).datepicker({ defaultDate: "", dateFormat: "yy-mm-dd", numberOfMonths: 1, minDate: "-12M", maxDate: "+0D", showButtonPanel: true, showOn: "button", buttonImage: "plugin_url(); ?>/assets/images/calendar.png", buttonImageOnly: true, onSelect: function( selectedDate ) { var option = this.id == "from" ? "minDate" : "maxDate", instance = jQuery( this ).data( "datepicker" ), date = jQuery.datepicker.parseDate( instance.settings.dateFormat || jQuery.datepicker._defaults.dateFormat, selectedDate, instance.settings ); dates.not( this ).datepicker( "option", option, date ); } }); get_row( " SELECT SUM(meta.meta_value) AS total_sales, COUNT(posts.ID) AS total_orders FROM {$wpdb->posts} AS posts LEFT JOIN {$wpdb->postmeta} AS meta ON posts.ID = meta.post_id LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID=rel.object_ID LEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id ) LEFT JOIN {$wpdb->terms} AS term USING( term_id ) WHERE meta.meta_key = '_order_total' AND posts.post_type = 'shop_order' AND posts.post_status = 'publish' AND tax.taxonomy = 'shop_order_status' AND term.slug IN ('" . implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ) . "') " ) ); $total_sales = $order_totals->total_sales; $total_orders = absint( $order_totals->total_orders ); $discount_total = apply_filters( 'woocommerce_reports_sales_overview_discount_total', $wpdb->get_var( " SELECT SUM(meta.meta_value) AS total_sales FROM {$wpdb->posts} AS posts LEFT JOIN {$wpdb->postmeta} AS meta ON posts.ID = meta.post_id LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID=rel.object_ID LEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id ) LEFT JOIN {$wpdb->terms} AS term USING( term_id ) WHERE meta.meta_key IN ('_order_discount', '_cart_discount') AND posts.post_type = 'shop_order' AND posts.post_status = 'publish' AND tax.taxonomy = 'shop_order_status' AND term.slug IN ('" . implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ) . "') " ) ); $shipping_total = apply_filters( 'woocommerce_reports_sales_overview_shipping_total', $wpdb->get_var( " SELECT SUM(meta.meta_value) AS total_sales FROM {$wpdb->posts} AS posts LEFT JOIN {$wpdb->postmeta} AS meta ON posts.ID = meta.post_id LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID=rel.object_ID LEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id ) LEFT JOIN {$wpdb->terms} AS term USING( term_id ) WHERE meta.meta_key = '_order_shipping' AND posts.post_type = 'shop_order' AND posts.post_status = 'publish' AND tax.taxonomy = 'shop_order_status' AND term.slug IN ('" . implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ) . "') " ) ); $order_items = apply_filters( 'woocommerce_reports_sales_overview_order_items', absint( $wpdb->get_var( " SELECT SUM( order_item_meta.meta_value ) FROM {$wpdb->prefix}woocommerce_order_items as order_items LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id LEFT JOIN {$wpdb->posts} AS posts ON order_items.order_id = posts.ID LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID = rel.object_ID LEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id ) LEFT JOIN {$wpdb->terms} AS term USING( term_id ) WHERE term.slug IN ('" . implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ) . "') AND posts.post_status = 'publish' AND tax.taxonomy = 'shop_order_status' AND order_items.order_item_type = 'line_item' AND order_item_meta.meta_key = '_qty' " ) ) ); ?>

0) echo woocommerce_price($total_sales); else _e( 'n/a', 'woocommerce' ); ?>

0 ) echo $total_orders . ' (' . $order_items . ' ' . __( 'items', 'woocommerce' ) . ')'; else _e( 'n/a', 'woocommerce' ); ?>

0) echo woocommerce_price($total_sales/$total_orders); else _e( 'n/a', 'woocommerce' ); ?>

0) echo number_format($order_items/$total_orders, 2); else _e( 'n/a', 'woocommerce' ); ?>

0) echo woocommerce_price($discount_total); else _e( 'n/a', 'woocommerce' ); ?>

0) echo woocommerce_price($shipping_total); else _e( 'n/a', 'woocommerce' ); ?>

get_results( " SELECT posts.ID, posts.post_date FROM {$wpdb->posts} AS posts LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID = rel.object_ID LEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id ) LEFT JOIN {$wpdb->terms} AS term USING( term_id ) WHERE posts.post_type = 'shop_order' AND posts.post_status = 'publish' AND tax.taxonomy = 'shop_order_status' AND term.slug IN ('" . implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ) . "') AND post_date > '" . date('Y-m-d', $start_date ) . "' AND post_date < '" . date('Y-m-d', strtotime('+1 day', $end_date ) ) . "' ORDER BY post_date ASC " ) ); if ( $orders ) { foreach ( $orders as $order ) { $order_total = get_post_meta( $order->ID, '_order_total', true ); $time = strtotime( date( 'Ymd', strtotime( $order->post_date ) ) ) . '000'; if ( isset( $order_counts[ $time ] ) ) $order_counts[ $time ]++; else $order_counts[ $time ] = 1; if ( isset( $order_amounts[ $time ] ) ) $order_amounts[ $time ] = $order_amounts[ $time ] + $order_total; else $order_amounts[ $time ] = floatval( $order_total ); } } $order_counts_array = $order_amounts_array = array(); foreach ( $order_counts as $key => $count ) $order_counts_array[] = array( esc_js( $key ), esc_js( $count ) ); foreach ( $order_amounts as $key => $amount ) $order_amounts_array[] = array( esc_js( $key ), esc_js( $amount ) ); $order_data = array( 'order_counts' => $order_counts_array, 'order_amounts' => $order_amounts_array ); $chart_data = json_encode( $order_data ); ?> get_results( " SELECT posts.ID, posts.post_date, meta.meta_value AS total_sales FROM {$wpdb->posts} AS posts LEFT JOIN {$wpdb->postmeta} AS meta ON posts.ID = meta.post_id LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID = rel.object_ID LEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id ) LEFT JOIN {$wpdb->terms} AS term USING( term_id ) WHERE meta.meta_key = '_order_total' AND posts.post_type = 'shop_order' AND posts.post_status = 'publish' AND tax.taxonomy = 'shop_order_status' AND term.slug IN ('" . implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ) . "') AND post_date > '" . date('Y-m-d', $start_date ) . "' AND post_date < '" . date('Y-m-d', strtotime('+1 day', $end_date ) ) . "' GROUP BY posts.ID ORDER BY post_date ASC " ), $start_date, $end_date ); if ( $orders ) { $total_orders = sizeof( $orders ); foreach ( $orders as $order ) { // get order timestamp $time = strtotime( date( 'Ymd', strtotime( $order->post_date ) ) ) . '000'; // Add order total $total_sales += $order->total_sales; // Get items $order_items += apply_filters( 'woocommerce_reports_daily_sales_order_items', absint( $wpdb->get_var( $wpdb->prepare( " SELECT SUM( order_item_meta.meta_value ) FROM {$wpdb->prefix}woocommerce_order_items as order_items LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id WHERE order_id = %d AND order_items.order_item_type = 'line_item' AND order_item_meta.meta_key = '_qty' ", $order->ID ) ) ), $order->ID ); // Set times if ( isset( $order_counts[ $time ] ) ) $order_counts[ $time ]++; else $order_counts[ $time ] = 1; if ( isset( $order_amounts[ $time ] ) ) $order_amounts[ $time ] = $order_amounts[ $time ] + $order->total_sales; else $order_amounts[ $time ] = floatval( $order->total_sales ); } } ?>

0 ) echo woocommerce_price( $total_sales ); else _e( 'n/a', 'woocommerce' ); ?>

0 ) echo $total_orders . ' (' . $order_items . ' ' . __( 'items', 'woocommerce' ) . ')'; else _e( 'n/a', 'woocommerce' ); ?>

0 ) echo woocommerce_price( $total_sales / $total_orders ); else _e( 'n/a', 'woocommerce' ); ?>

0 ) echo number_format( $order_items / $total_orders, 2 ); else _e( 'n/a', 'woocommerce' ); ?>

$count ) $order_counts_array[] = array( esc_js( $key ), esc_js( $count ) ); foreach ( $order_amounts as $key => $amount ) $order_amounts_array[] = array( esc_js( $key ), esc_js( $amount ) ); $order_data = array( 'order_counts' => $order_counts_array, 'order_amounts' => $order_amounts_array ); $chart_data = json_encode($order_data); ?> get_var( "SELECT post_date FROM $wpdb->posts WHERE post_date != 0 ORDER BY post_date ASC LIMIT 1;" ); $first_year = $first_year ? date( 'Y', strtotime( $first_year ) ) : date('Y'); $current_year = isset( $_POST['show_year'] ) ? $_POST['show_year'] : date( 'Y', current_time( 'timestamp' ) ); $start_date = strtotime( $current_year . '0101' ); $total_sales = $total_orders = $order_items = 0; $order_counts = $order_amounts = array(); for ( $count = 0; $count < 12; $count++ ) { $time = strtotime( date('Ym', strtotime( '+ ' . $count . ' MONTH', $start_date ) ) . '01' ) . '000'; if ( $time > current_time( 'timestamp' ) . '000' ) continue; $month = date( 'Ym', strtotime(date('Ym', strtotime('+ '.$count.' MONTH', $start_date)).'01') ); $months_orders = apply_filters( 'woocommerce_reports_monthly_sales_orders', $wpdb->get_row( $wpdb->prepare( " SELECT SUM(meta.meta_value) AS total_sales, COUNT(posts.ID) AS total_orders FROM {$wpdb->posts} AS posts LEFT JOIN {$wpdb->postmeta} AS meta ON posts.ID = meta.post_id LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID=rel.object_ID LEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id ) LEFT JOIN {$wpdb->terms} AS term USING( term_id ) WHERE meta.meta_key = '_order_total' AND posts.post_type = 'shop_order' AND posts.post_status = 'publish' AND tax.taxonomy = 'shop_order_status' AND term.slug IN ('" . implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ) . "') AND %s = date_format(posts.post_date,'%%Y%%m') ", $month ) ), $month ); $order_counts[ $time ] = (int) $months_orders->total_orders; $order_amounts[ $time ] = (float) $months_orders->total_sales; $total_orders += (int) $months_orders->total_orders; $total_sales += (float) $months_orders->total_sales; // Count order items $order_items += apply_filters( 'woocommerce_reports_monthly_sales_order_items', absint( $wpdb->get_var( $wpdb->prepare( " SELECT SUM( order_item_meta.meta_value ) FROM {$wpdb->prefix}woocommerce_order_items as order_items LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id LEFT JOIN {$wpdb->posts} AS posts ON order_items.order_id = posts.ID LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID = rel.object_ID LEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id ) LEFT JOIN {$wpdb->terms} AS term USING( term_id ) WHERE term.slug IN ('" . implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ) . "') AND posts.post_status = 'publish' AND tax.taxonomy = 'shop_order_status' AND %s = date_format( posts.post_date, '%%Y%%m' ) AND order_items.order_item_type = 'line_item' AND order_item_meta.meta_key = '_qty' ", $month ) ) ), $month ); } ?>

0) echo woocommerce_price($total_sales); else _e( 'n/a', 'woocommerce' ); ?>

0 ) echo $total_orders . ' (' . $order_items . ' ' . __( 'items', 'woocommerce' ) . ')'; else _e( 'n/a', 'woocommerce' ); ?>

0) echo woocommerce_price($total_sales/$total_orders); else _e( 'n/a', 'woocommerce' ); ?>

0) echo number_format($order_items/$total_orders, 2); else _e( 'n/a', 'woocommerce' ); ?>

$count ) $order_counts_array[] = array( esc_js( $key ), esc_js( $count ) ); foreach ( $order_amounts as $key => $amount ) $order_amounts_array[] = array( esc_js( $key ), esc_js( $amount ) ); $order_data = array( 'order_counts' => $order_counts_array, 'order_amounts' => $order_amounts_array ); $chart_data = json_encode( $order_data ); ?> get_results( " SELECT order_item_meta_2.meta_value as product_id, SUM( order_item_meta.meta_value ) as item_quantity FROM {$wpdb->prefix}woocommerce_order_items as order_items LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta_2 ON order_items.order_item_id = order_item_meta_2.order_item_id LEFT JOIN {$wpdb->posts} AS posts ON order_items.order_id = posts.ID LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID = rel.object_ID LEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id ) LEFT JOIN {$wpdb->terms} AS term USING( term_id ) WHERE posts.post_type = 'shop_order' AND posts.post_status = 'publish' AND tax.taxonomy = 'shop_order_status' AND term.slug IN ('" . implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ) . "') AND post_date > '" . date('Y-m-d', $start_date ) . "' AND post_date < '" . date('Y-m-d', strtotime('+1 day', $end_date ) ) . "' AND order_items.order_item_type = 'line_item' AND order_item_meta.meta_key = '_qty' AND order_item_meta_2.meta_key = '_product_id' GROUP BY order_item_meta_2.meta_value " ), $start_date, $end_date ); $found_products = array(); if ( $order_items ) { foreach ( $order_items as $order_item ) { $found_products[ $order_item->product_id ] = $order_item->item_quantity; } } asort( $found_products ); $found_products = array_reverse( $found_products, true ); $found_products = array_slice( $found_products, 0, 25, true ); reset( $found_products ); ?>

$sales ) { $width = $sales > 0 ? ( $sales / $max_sales ) * 100 : 0; $product_title = get_the_title( $product_id ); if ( $product_title ) { $product_name = ''. __( $product_title ) .''; $orders_link = admin_url( 'edit.php?s&post_status=all&post_type=shop_order&action=-1&s=' . urlencode( $product_title ) . '&shop_order_status=completed,processing,on-hold' ); } else { $product_name = __( 'Product does not exist', 'woocommerce' ); $orders_link = admin_url( 'edit.php?s&post_status=all&post_type=shop_order&action=-1&s=&shop_order_status=completed,processing,on-hold' ); } echo ''; } ?>
' . $product_name . '' . esc_html( $sales ) . ' 
get_results( " SELECT order_item_meta_2.meta_value as product_id, SUM( order_item_meta.meta_value ) as line_total FROM {$wpdb->prefix}woocommerce_order_items as order_items LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta_2 ON order_items.order_item_id = order_item_meta_2.order_item_id LEFT JOIN {$wpdb->posts} AS posts ON order_items.order_id = posts.ID LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID = rel.object_ID LEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id ) LEFT JOIN {$wpdb->terms} AS term USING( term_id ) WHERE posts.post_type = 'shop_order' AND posts.post_status = 'publish' AND tax.taxonomy = 'shop_order_status' AND term.slug IN ('" . implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ) . "') AND post_date > '" . date('Y-m-d', $start_date ) . "' AND post_date < '" . date('Y-m-d', strtotime('+1 day', $end_date ) ) . "' AND order_items.order_item_type = 'line_item' AND order_item_meta.meta_key = '_line_total' AND order_item_meta_2.meta_key = '_product_id' GROUP BY order_item_meta_2.meta_value " ), $start_date, $end_date ); $found_products = array(); if ( $order_items ) { foreach ( $order_items as $order_item ) { $found_products[ $order_item->product_id ] = $order_item->line_total; } } asort( $found_products ); $found_products = array_reverse( $found_products, true ); $found_products = array_slice( $found_products, 0, 25, true ); reset( $found_products ); ?>

$sales ) { $width = $sales > 0 ? ( round( $sales ) / round( $max_sales ) ) * 100 : 0; $product_title = get_the_title( $product_id ); if ( $product_title ) { $product_name = ''. __( $product_title ) .''; $orders_link = admin_url( 'edit.php?s&post_status=all&post_type=shop_order&action=-1&s=' . urlencode( $product_title ) . '&shop_order_status=completed,processing,on-hold' ); } else { $product_name = __( 'Product no longer exists', 'woocommerce' ); $orders_link = admin_url( 'edit.php?s&post_status=all&post_type=shop_order&action=-1&s=&shop_order_status=completed,processing,on-hold' ); } echo ''; } ?>
' . $product_name . '' . woocommerce_price( $sales ) . ' 
get_results( " SELECT order_item_meta_2.meta_value as product_id, posts.post_date, SUM( order_item_meta.meta_value ) as item_quantity, SUM( order_item_meta_3.meta_value ) as line_total FROM {$wpdb->prefix}woocommerce_order_items as order_items LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta_2 ON order_items.order_item_id = order_item_meta_2.order_item_id LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta_3 ON order_items.order_item_id = order_item_meta_3.order_item_id LEFT JOIN {$wpdb->posts} AS posts ON order_items.order_id = posts.ID LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID = rel.object_ID LEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id ) LEFT JOIN {$wpdb->terms} AS term USING( term_id ) WHERE posts.post_type = 'shop_order' AND order_item_meta_2.meta_value IN ('" . implode( "','", array_merge( $chosen_product_ids, $children_ids ) ) . "') AND posts.post_status = 'publish' AND tax.taxonomy = 'shop_order_status' AND term.slug IN ('" . implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ) . "') AND order_items.order_item_type = 'line_item' AND order_item_meta.meta_key = '_qty' AND order_item_meta_2.meta_key = '_product_id' AND order_item_meta_3.meta_key = '_line_total' GROUP BY order_items.order_id ORDER BY posts.post_date ASC " ), array_merge( $chosen_product_ids, $children_ids ) ); $found_products = array(); if ( $order_items ) { foreach ( $order_items as $order_item ) { if ( $order_item->line_total == 0 && $order_item->item_quantity == 0 ) continue; // Get date $date = date( 'Ym', strtotime( $order_item->post_date ) ); // Set values $product_sales[ $date ] = isset( $product_sales[ $date ] ) ? $product_sales[ $date ] + $order_item->item_quantity : $order_item->item_quantity; $product_totals[ $date ] = isset( $product_totals[ $date ] ) ? $product_totals[ $date ] + $order_item->line_total : $order_item->line_total; if ( $product_sales[ $date ] > $max_sales ) $max_sales = $product_sales[ $date ]; if ( $product_totals[ $date ] > $max_totals ) $max_totals = $product_totals[ $date ]; } } ?>

0 ) { foreach ( $product_sales as $date => $sales ) { $width = ($sales>0) ? (round($sales) / round($max_sales)) * 100 : 0; $width2 = ($product_totals[$date]>0) ? (round($product_totals[$date]) / round($max_totals)) * 100 : 0; $orders_link = admin_url( 'edit.php?s&post_status=all&post_type=shop_order&action=-1&s=' . urlencode( implode( ' ', $chosen_product_titles ) ) . '&m=' . date( 'Ym', strtotime( $date . '01' ) ) . '&shop_order_status=completed,processing,on-hold' ); echo ''; } } else { echo ''; } ?>
' . date_i18n( 'F', strtotime( $date . '01' ) ) . ' ' . esc_html( $sales ) . '' . woocommerce_price( $product_totals[ $date ] ) . '    
' . __( 'No sales :(', 'woocommerce' ) . '

array('user_registered'), 'role' => 'customer' ) ); $customers = $users_query->get_results(); $total_customers = (int) sizeof($customers); $customer_orders = apply_filters( 'woocommerce_reports_customer_overview_customer_orders', $wpdb->get_row( " SELECT SUM(meta.meta_value) AS total_sales, COUNT(posts.ID) AS total_orders FROM {$wpdb->posts} AS posts LEFT JOIN {$wpdb->postmeta} AS meta ON posts.ID = meta.post_id LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID=rel.object_ID LEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id ) LEFT JOIN {$wpdb->terms} AS term USING( term_id ) WHERE meta.meta_key = '_order_total' AND posts.post_type = 'shop_order' AND posts.post_status = 'publish' AND tax.taxonomy = 'shop_order_status' AND term.slug IN ('" . implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ) . "') AND posts.ID IN ( SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = '_customer_user' AND meta_value > 0 ) " ) ); $total_customer_sales = $customer_orders->total_sales; $total_customer_orders = absint( $customer_orders->total_orders ); $guest_orders = apply_filters( 'woocommerce_reports_customer_overview_guest_orders', $wpdb->get_row( " SELECT SUM(meta.meta_value) AS total_sales, COUNT(posts.ID) AS total_orders FROM {$wpdb->posts} AS posts LEFT JOIN {$wpdb->postmeta} AS meta ON posts.ID = meta.post_id LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID=rel.object_ID LEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id ) LEFT JOIN {$wpdb->terms} AS term USING( term_id ) WHERE meta.meta_key = '_order_total' AND posts.post_type = 'shop_order' AND posts.post_status = 'publish' AND tax.taxonomy = 'shop_order_status' AND term.slug IN ('" . implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ) . "') AND posts.ID IN ( SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = '_customer_user' AND meta_value = 0 ) " ) ); $total_guest_sales = $guest_orders->total_sales; $total_guest_orders = absint( $guest_orders->total_orders ); ?>

0) echo $total_customers; else _e( 'n/a', 'woocommerce' ); ?>

0) echo woocommerce_price($total_customer_sales); else _e( 'n/a', 'woocommerce' ); ?>

0) echo woocommerce_price($total_guest_sales); else _e( 'n/a', 'woocommerce' ); ?>

0) echo $total_customer_orders; else _e( 'n/a', 'woocommerce' ); ?>

0) echo $total_guest_orders; else _e( 'n/a', 'woocommerce' ); ?>

0 && $total_customers>0) echo number_format($total_customer_orders/$total_customers, 2); else _e( 'n/a', 'woocommerce' ); ?>

user_registered) > $start_date) : $time = strtotime(date('Ymd', strtotime($customer->user_registered))).'000'; if (isset($signups[ $time ])) : $signups[ $time ]++; else : $signups[ $time ] = 1; endif; endif; endforeach; $signups_array = array(); foreach ($signups as $key => $count) : $signups_array[] = array( esc_js( $key ), esc_js( $count ) ); endforeach; $chart_data = json_encode($signups_array); ?> 'product', 'post_status' => 'publish', 'posts_per_page' => -1, 'meta_query' => array( array( 'key' => '_manage_stock', 'value' => 'yes' ), array( 'key' => '_stock', 'value' => $lowstockamount, 'compare' => '<=', 'type' => 'NUMERIC' ) ), 'tax_query' => array( array( 'taxonomy' => 'product_type', 'field' => 'slug', 'terms' => array('simple'), 'operator' => 'IN' ) ) ); $low_stock_products = (array) get_posts($args); // Get low stock product variations $args = array( 'post_type' => 'product_variation', 'post_status' => 'publish', 'posts_per_page' => -1, 'meta_query' => array( array( 'key' => '_stock', 'value' => $lowstockamount, 'compare' => '<=', 'type' => 'NUMERIC' ), array( 'key' => '_stock', 'value' => array('', false, null), 'compare' => 'NOT IN' ) ) ); $low_stock_variations = (array) get_posts($args); // Finally, get low stock variable products (where stock is set for the parent) $args = array( 'post_type' => array('product'), 'post_status' => 'publish', 'posts_per_page' => -1, 'meta_query' => array( 'relation' => 'AND', array( 'key' => '_manage_stock', 'value' => 'yes' ), array( 'key' => '_stock', 'value' => $lowstockamount, 'compare' => '<=', 'type' => 'NUMERIC' ) ), 'tax_query' => array( array( 'taxonomy' => 'product_type', 'field' => 'slug', 'terms' => array('variable'), 'operator' => 'IN' ) ) ); $low_stock_variable_products = (array) get_posts($args); // Merge results $low_in_stock = array_merge($low_stock_products, $low_stock_variations, $low_stock_variable_products); ?>

'; foreach ( $low_in_stock as $product ) { $stock = (int) get_post_meta( $product->ID, '_stock', true ); $sku = get_post_meta( $product->ID, '_sku', true ); if ( $stock <= $nostockamount ) continue; $title = esc_html__( $product->post_title ); if ( $sku ) $title .= ' (' . __( 'SKU', 'woocommerce' ) . ': ' . esc_html( $sku ) . ')'; if ( $product->post_type=='product' ) $product_url = admin_url( 'post.php?post=' . $product->ID . '&action=edit' ); else $product_url = admin_url( 'post.php?post=' . $product->post_parent . '&action=edit' ); printf( '
  • ' . _n('%d in stock', '%d in stock', $stock, 'woocommerce') . ' %s
  • ', $product_url, $stock, $title ); } echo ''; } else { echo '

    '.__( 'No products are low in stock.', 'woocommerce' ).'

    '; } ?>

    '; foreach ( $low_in_stock as $product ) { $stock = (int) get_post_meta( $product->ID, '_stock', true ); $sku = get_post_meta( $product->ID, '_sku', true ); if ( $stock > $nostockamount ) continue; $title = esc_html__( $product->post_title ); if ( $sku ) $title .= ' (' . __( 'SKU', 'woocommerce' ) . ': ' . esc_html( $sku ) . ')'; if ( $product->post_type=='product' ) $product_url = admin_url( 'post.php?post=' . $product->ID . '&action=edit' ); else $product_url = admin_url( 'post.php?post=' . $product->post_parent . '&action=edit' ); printf( '
  • ' . _n('%d in stock', '%d in stock', $stock, 'woocommerce') . ' %s
  • ', $product_url, $stock, $title ); } echo ''; } else { echo '

    '.__( 'No products are out in stock.', 'woocommerce' ).'

    '; } ?>
    get_var( "SELECT post_date FROM $wpdb->posts WHERE post_date != 0 ORDER BY post_date ASC LIMIT 1;" ); if ( $first_year ) $first_year = date( 'Y', strtotime( $first_year ) ); else $first_year = date( 'Y' ); $current_year = isset( $_POST['show_year'] ) ? $_POST['show_year'] : date( 'Y', current_time( 'timestamp' ) ); $start_date = strtotime( $current_year . '0101' ); $total_tax = $total_sales_tax = $total_shipping_tax = $count = 0; $taxes = $tax_rows = $tax_row_labels = array(); for ( $count = 0; $count < 12; $count++ ) { $time = strtotime( date('Ym', strtotime( '+ ' . $count . ' MONTH', $start_date ) ) . '01' ); if ( $time > current_time( 'timestamp' ) ) continue; $month = date( 'Ym', strtotime( date( 'Ym', strtotime( '+ ' . $count . ' MONTH', $start_date ) ) . '01' ) ); $gross = $wpdb->get_var( $wpdb->prepare( " SELECT SUM( meta.meta_value ) AS order_tax FROM {$wpdb->posts} AS posts LEFT JOIN {$wpdb->postmeta} AS meta ON posts.ID = meta.post_id LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID=rel.object_ID LEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id ) LEFT JOIN {$wpdb->terms} AS term USING( term_id ) WHERE meta.meta_key = '_order_total' AND posts.post_type = 'shop_order' AND posts.post_status = 'publish' AND tax.taxonomy = 'shop_order_status' AND term.slug IN ('" . implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ) . "') AND %s = date_format(posts.post_date,'%%Y%%m') ", $month ) ); $shipping = $wpdb->get_var( $wpdb->prepare( " SELECT SUM( meta.meta_value ) AS order_tax FROM {$wpdb->posts} AS posts LEFT JOIN {$wpdb->postmeta} AS meta ON posts.ID = meta.post_id LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID=rel.object_ID LEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id ) LEFT JOIN {$wpdb->terms} AS term USING( term_id ) WHERE meta.meta_key = '_order_shipping' AND posts.post_type = 'shop_order' AND posts.post_status = 'publish' AND tax.taxonomy = 'shop_order_status' AND term.slug IN ('" . implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ) . "') AND %s = date_format(posts.post_date,'%%Y%%m') ", $month ) ); $order_tax = $wpdb->get_var( $wpdb->prepare( " SELECT SUM( meta.meta_value ) AS order_tax FROM {$wpdb->posts} AS posts LEFT JOIN {$wpdb->postmeta} AS meta ON posts.ID = meta.post_id LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID=rel.object_ID LEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id ) LEFT JOIN {$wpdb->terms} AS term USING( term_id ) WHERE meta.meta_key = '_order_tax' AND posts.post_type = 'shop_order' AND posts.post_status = 'publish' AND tax.taxonomy = 'shop_order_status' AND term.slug IN ('" . implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ) . "') AND %s = date_format(posts.post_date,'%%Y%%m') ", $month ) ); $shipping_tax = $wpdb->get_var( $wpdb->prepare( " SELECT SUM( meta.meta_value ) AS order_tax FROM {$wpdb->posts} AS posts LEFT JOIN {$wpdb->postmeta} AS meta ON posts.ID = meta.post_id LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID=rel.object_ID LEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id ) LEFT JOIN {$wpdb->terms} AS term USING( term_id ) WHERE meta.meta_key = '_order_shipping_tax' AND posts.post_type = 'shop_order' AND posts.post_status = 'publish' AND tax.taxonomy = 'shop_order_status' AND term.slug IN ('" . implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ) . "') AND %s = date_format(posts.post_date,'%%Y%%m') ", $month ) ); $tax_rows = $wpdb->get_results( $wpdb->prepare( " SELECT order_items.order_item_name as name, SUM( order_item_meta.meta_value ) as tax_amount, SUM( order_item_meta_2.meta_value ) as shipping_tax_amount, SUM( order_item_meta.meta_value + order_item_meta_2.meta_value ) as total_tax_amount FROM {$wpdb->prefix}woocommerce_order_items as order_items LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta_2 ON order_items.order_item_id = order_item_meta_2.order_item_id LEFT JOIN {$wpdb->posts} AS posts ON order_items.order_id = posts.ID LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID = rel.object_ID LEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id ) LEFT JOIN {$wpdb->terms} AS term USING( term_id ) WHERE order_items.order_item_type = 'tax' AND posts.post_type = 'shop_order' AND posts.post_status = 'publish' AND tax.taxonomy = 'shop_order_status' AND term.slug IN ('" . implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ) . "') AND %s = date_format( posts.post_date,'%%Y%%m' ) AND order_item_meta.meta_key = 'tax_amount' AND order_item_meta_2.meta_key = 'shipping_tax_amount' GROUP BY order_items.order_item_name ", $month ) ); if ( $tax_rows ) { foreach ( $tax_rows as $tax_row ) { $tax_row_labels[] = $tax_row->name; } } $taxes[ date( 'M', strtotime( $month . '01' ) ) ] = array( 'gross' => $gross, 'shipping' => $shipping, 'order_tax' => $order_tax, 'shipping_tax' => $shipping_tax, 'total_tax' => $shipping_tax + $order_tax, 'tax_rows' => $tax_rows ); $total_sales_tax += $order_tax; $total_shipping_tax += $shipping_tax; } $total_tax = $total_sales_tax + $total_shipping_tax; ?>

    0 ) echo woocommerce_price( $total_tax ); else _e( 'n/a', 'woocommerce' ); ?>

    0 ) echo woocommerce_price( $total_sales_tax ); else _e( 'n/a', 'woocommerce' ); ?>

    0 ) echo woocommerce_price( $total_shipping_tax ); else _e( 'n/a', 'woocommerce' ); ?>

    ' . $label . ''; ?> $tax ) { $total['gross'] = isset( $total['gross'] ) ? $total['gross'] + $tax['gross'] : $tax['gross']; $total['shipping'] = isset( $total['shipping'] ) ? $total['shipping'] + $tax['shipping'] : $tax['shipping']; $total['order_tax'] = isset( $total['order_tax'] ) ? $total['order_tax'] + $tax['order_tax'] : $tax['order_tax']; $total['shipping_tax'] = isset( $total['shipping_tax'] ) ? $total['shipping_tax'] + $tax['shipping_tax'] : $tax['shipping_tax']; $total['total_tax'] = isset( $total['total_tax'] ) ? $total['total_tax'] + $tax['total_tax'] : $tax['total_tax']; foreach ( $tax_row_labels as $label ) foreach ( $tax['tax_rows'] as $tax_row ) if ( $tax_row->name == $label ) { $total['tax_rows'][ $label ] = isset( $total['tax_rows'][ $label ] ) ? $total['tax_rows'][ $label ] + $tax_row->total_tax_amount : $tax_row->total_tax_amount; } } echo ' '; foreach ( $tax_row_labels as $label ) if ( isset( $total['tax_rows'][ $label ] ) ) echo ''; else echo ''; ?> $tax ) { $alt = ( isset( $alt ) && $alt == 'alt' ) ? '' : 'alt'; echo ''; foreach ( $tax_row_labels as $label ) { $row_total = 0; foreach ( $tax['tax_rows'] as $tax_row ) { if ( $tax_row->name == $label ) { $row_total = $tax_row->total_tax_amount; } } echo ''; } echo ''; } ?>
    " href="#">[?] " href="#">[?] " href="#">[?] " href="#">[?] " href="#">[?] " href="#">[?]
    ' . __( 'Total', 'woocommerce' ) . ' ' . woocommerce_price( $total['gross'] ) . ' ' . woocommerce_price( $total['shipping'] ) . ' ' . woocommerce_price( $total['order_tax'] ) . ' ' . woocommerce_price( $total['shipping_tax'] ) . ' ' . woocommerce_price( $total['total_tax'] ) . ' ' . woocommerce_price( $total['gross'] - $total['shipping'] - $total['total_tax'] ) . '' . woocommerce_price( $total['tax_rows'][ $label ] ) . '' . woocommerce_price( 0 ) . '
    ' . $month . ' ' . woocommerce_price( $tax['gross'] ) . ' ' . woocommerce_price( $tax['shipping'] ) . ' ' . woocommerce_price( $tax['order_tax'] ) . ' ' . woocommerce_price( $tax['shipping_tax'] ) . ' ' . woocommerce_price( $tax['total_tax'] ) . ' ' . woocommerce_price( $tax['gross'] - $tax['shipping'] - $tax['total_tax'] ) . '' . woocommerce_price( $row_total ) . '
    get_var( "SELECT post_date FROM $wpdb->posts WHERE post_date != 0 ORDER BY post_date ASC LIMIT 1;" ); $first_year = ( $first_year ) ? date( 'Y', strtotime( $first_year ) ) : date( 'Y' ); $current_year = isset( $_POST['show_year'] ) ? $_POST['show_year'] : date( 'Y', current_time( 'timestamp' ) ); $start_date = strtotime( $current_year . '0101' ); $categories = get_terms( 'product_cat', array( 'orderby' => 'name' ) ); ?>

    get_results( $wpdb->prepare( " SELECT order_item_meta_2.meta_value as product_id, posts.post_date, SUM( order_item_meta.meta_value ) as line_total FROM {$wpdb->prefix}woocommerce_order_items as order_items LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta_2 ON order_items.order_item_id = order_item_meta_2.order_item_id LEFT JOIN {$wpdb->posts} AS posts ON order_items.order_id = posts.ID LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID = rel.object_ID LEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id ) LEFT JOIN {$wpdb->terms} AS term USING( term_id ) WHERE posts.post_type = 'shop_order' AND posts.post_status = 'publish' AND tax.taxonomy = 'shop_order_status' AND term.slug IN ('" . implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ) . "') AND date_format(posts.post_date,'%%Y%%m') >= %s AND order_items.order_item_type = 'line_item' AND order_item_meta.meta_key = '_line_total' AND order_item_meta_2.meta_key = '_product_id' GROUP BY order_items.order_id ORDER BY posts.post_date ASC ", $start_date ) ) ); if ( $order_items ) { foreach ( $order_items as $order_item ) { $month = date( 'm', strtotime( $order_item->post_date ) ) - 1; $item_sales[ $month ][ $order_item->product_id ] = isset( $item_sales[ $month ][ $order_item->product_id ] ) ? $item_sales[ $month ][ $order_item->product_id ] + $order_item->line_total : $order_item->line_total; } } if ( ! empty( $_POST['show_categories'] ) && sizeof( $_POST['show_categories'] ) > 0 ) { $show_categories = $include_categories = array_map( 'absint', $_POST['show_categories'] ); foreach( $show_categories as $cat ) $include_categories = array_merge( $include_categories, get_term_children( $cat, 'product_cat' ) ); $categories = get_terms( 'product_cat', array( 'include' => array_unique( $include_categories ) ) ); ?>
    = date ( 'm' ) && $current_year == date( 'Y' ) ) continue; $column_count++; ?> = date( 'm' ) && $current_year == date( 'Y' ) ) break; else $month_totals[ $count ] = 0; foreach ( $categories as $category ) { $cat_total = 0; $category_chart_data = $term_ids = array(); $term_ids = get_term_children( $category->term_id, 'product_cat' ); $term_ids[] = $category->term_id; $product_ids = get_objects_in_term( $term_ids, 'product_cat' ); if ( $category->parent > 0 ) $prepend = '— '; else $prepend = ''; $category_sales_html = ''; for ( $count = 0; $count < 12; $count++ ) { if ( $count >= date( 'm' ) && $current_year == date( 'Y' ) ) continue; if ( ! empty( $item_sales[ $count ] ) ) { $matches = array_intersect_key( $item_sales[ $count ], array_flip( $product_ids ) ); $total = array_sum( $matches ); $cat_total += $total; } else { $total = 0; } $month_totals[ $count ] += $total; $category_sales_html .= ''; $category_chart_data[] = array( strtotime( date( 'Ymd', strtotime( '2012-' . ( $count + 1 ) . '-01' ) ) ) . '000', $total ); } if ( $cat_total == 0 ) continue; $category_totals[] = $cat_total; $category_sales_html .= ''; $category_sales_html .= ''; echo $category_sales_html; $chart_data[ $category->name ] = $category_chart_data; if ( $cat_total > $top_cat ) { $top_cat = $cat_total; $top_cat_name = $category->name; } if ( $cat_total < $bottom_cat || $bottom_cat === '' ) { $bottom_cat = $cat_total; $bottom_cat_name = $category->name; } } sort( $category_totals ); echo ''; for ( $count = 0; $count < 12; $count++ ) if ( $count >= date( 'm' ) && $current_year == date( 'Y' ) ) break; else echo ''; echo ''; ?>
    ' . $prepend . $category->name . '' . woocommerce_price( $total ) . '' . woocommerce_price( $cat_total ) . '
    ' . __( 'Total', 'woocommerce' ) . '' . woocommerce_price( $month_totals[ $count ] ) . '' . woocommerce_price( array_sum( $month_totals ) ) . '

    1 ) : ?>

    0 ) echo woocommerce_price( array_sum( $category_totals ) / sizeof( $category_totals ) ); else echo __( 'N/A', 'woocommerce' ); ?>

    get_var( "SELECT post_date FROM $wpdb->posts WHERE post_date != 0 AND post_type='shop_order' ORDER BY post_date ASC LIMIT 1;" ); $first_year = ( $first_year ) ? date( 'Y', strtotime( $first_year ) ) : date( 'Y' ); $current_year = isset( $_POST['show_year'] ) ? $_POST['show_year'] : date( 'Y', current_time( 'timestamp' ) ); $start_date = strtotime( $current_year . '0101' ); $order_statuses = implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ); $coupons = $wpdb->get_col( " SELECT DISTINCT meta.meta_value FROM {$wpdb->postmeta} AS meta LEFT JOIN {$wpdb->posts} AS posts ON posts.ID = meta.post_id LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID=rel.object_ID LEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id ) LEFT JOIN {$wpdb->terms} AS term USING( term_id ) WHERE meta.meta_key = 'coupons' AND posts.post_type = 'shop_order' AND posts.post_status = 'publish' AND tax.taxonomy = 'shop_order_status' AND term.slug IN ('{$order_statuses}') " ); ?>

    0 ) : $coupons = $_POST['show_coupons']; $coupon_sales = $monthly_totals = array(); foreach( $coupons as $coupon ) : $monthly_sales = apply_filters( 'woocommerce_reports_coupon_sales_order_totals', $wpdb->get_results( $wpdb->prepare( " SELECT SUM(postmeta.meta_value) AS order_total, date_format(posts.post_date, '%%Y%%m') as month FROM {$wpdb->posts} AS posts INNER JOIN {$wpdb->postmeta} AS postmeta ON posts.ID=postmeta.post_ID INNER JOIN {$wpdb->term_relationships} AS rel ON posts.ID=rel.object_ID INNER JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id ) INNER JOIN {$wpdb->terms} AS term USING( term_id ) WHERE postmeta.meta_key = '_order_total' AND tax.taxonomy = 'shop_order_status' AND term.slug IN ('{$order_statuses}') AND posts.post_type = 'shop_order' AND posts.post_status = 'publish' AND '{$current_year}' = date_format(posts.post_date,'%%Y') AND posts.ID IN ( SELECT post_id FROM {$wpdb->postmeta} AS meta WHERE meta.meta_key = 'coupons' AND meta.meta_value = '%s' ) GROUP BY month", $coupon ), OBJECT ), $order_statuses, $current_year, $coupon); foreach( $monthly_sales as $sales ) { $month = $sales->month; $coupon_sales[$coupon][$month] = $sales->order_total; } endforeach; ?>
    = date ( 'm' ) && $current_year == date( 'Y' ) ) continue; $month = date( 'Ym', strtotime( date( 'Ym', strtotime( '+ '. $count . ' MONTH', $start_date ) ) . '01' ) ); // set elements before += them below $monthly_totals[$month] = 0; $column_count++; ?> $sales ) { echo ''; for ( $count = 0; $count < 12; $count ++ ) { if ( $count >= date ( 'm' ) && $current_year == date( 'Y' ) ) continue; $month = date( 'Ym', strtotime( date( 'Ym', strtotime( '+ '. $count . ' MONTH', $start_date ) ) . '01' ) ); $amount = isset( $sales[$month] ) ? $sales[$month] : 0; echo ''; $monthly_totals[$month] += $amount; $chart_data[$coupon_code][] = array( strtotime( date( 'Ymd', strtotime( $month . '01' ) ) ) . '000', $amount ); } echo ''; // total sales across all months $coupon_totals[$coupon_code] = array_sum( $sales ); echo ''; } $top_coupon_name = current( array_keys( $coupon_totals, max( $coupon_totals ) ) ); $top_coupon_sales = $coupon_totals[$top_coupon_name]; $worst_coupon_name = current( array_keys( $coupon_totals, min( $coupon_totals ) ) ); $worst_coupon_sales = $coupon_totals[$worst_coupon_name]; $median_coupon_sales = array_values( $coupon_totals ); sort($median_coupon_sales); echo ''; foreach( $monthly_totals as $month => $totals ) echo ''; echo ''; ?>
    ' . esc_html( $coupon_code ) . '' . woocommerce_price( $amount ) . '' . woocommerce_price( array_sum( $sales ) ) . '
    ' . __( 'Total', 'woocommerce' ) . '' . woocommerce_price( $totals ) . '' . woocommerce_price( array_sum( $monthly_totals ) ) . '

    1 ) : ?>