Sales by product
This commit is contained in:
parent
dcee729de4
commit
b9837c2ecd
|
@ -79,22 +79,11 @@ class WC_Admin_Reports {
|
|||
'hide_title' => true,
|
||||
'callback' => array( $this, 'get_report' )
|
||||
),
|
||||
"top_sellers" => array(
|
||||
'title' => __( 'Top Sellers', 'woocommerce' ),
|
||||
'description' => '',
|
||||
'hide_title' => true,
|
||||
'callback' => array( $this, 'get_report' )
|
||||
),
|
||||
"top_earners" => array(
|
||||
'title' => __( 'Top Earners', 'woocommerce' ),
|
||||
'description' => '',
|
||||
'hide_title' => true,
|
||||
'callback' => array( $this, 'get_report' )
|
||||
),
|
||||
"sales_by_product" => array(
|
||||
'title' => __( 'Sales by product', 'woocommerce' ),
|
||||
'description' => '',
|
||||
'callback' => 'woocommerce_product_sales'
|
||||
'hide_title' => true,
|
||||
'callback' => array( $this, 'get_report' )
|
||||
),
|
||||
"sales_by_category" => array(
|
||||
'title' => __( 'Sales by category', 'woocommerce' ),
|
||||
|
@ -218,59 +207,6 @@ new WC_Admin_Reports();
|
|||
|
||||
|
||||
/*
|
||||
<li class="item">
|
||||
<h4><?php _e( 'Product Sales', 'woocommerce' ); ?></h4>
|
||||
<?php
|
||||
if ( ! empty( $product_id_filter ) ) {
|
||||
|
||||
$product_id_filter_titles = array();
|
||||
|
||||
foreach ( $product_id_filter as $product_id ) {
|
||||
$product_id_filter_titles[] = get_the_title( $product_id );
|
||||
}
|
||||
|
||||
echo '<p>' . __( 'Showing reports for:' ) . ' <strong>' . implode( ', ', $product_id_filter_titles ) . '</strong></p>';
|
||||
|
||||
} else {
|
||||
?>
|
||||
<form method="GET">
|
||||
<div>
|
||||
<select id="product_ids" name="product_ids[]" class="ajax_chosen_select_products" multiple="multiple" data-placeholder="<?php _e( 'Search for a product…', 'woocommerce' ); ?>"></select>
|
||||
<input type="submit" class="button" value="<?php _e( 'Show', 'woocommerce' ); ?>" />
|
||||
<input type="hidden" name="range" value="<?php if ( ! empty( $_GET['range'] ) ) echo esc_attr( $_GET['range'] ) ?>" />
|
||||
<input type="hidden" name="start_date" value="<?php if ( ! empty( $_GET['start_date'] ) ) echo esc_attr( $_GET['start_date'] ) ?>" />
|
||||
<input type="hidden" name="end_date" value="<?php if ( ! empty( $_GET['end_date'] ) ) echo esc_attr( $_GET['end_date'] ) ?>" />
|
||||
<input type="hidden" name="page" value="<?php if ( ! empty( $_GET['page'] ) ) echo esc_attr( $_GET['page'] ) ?>" />
|
||||
<input type="hidden" name="tab" value="<?php if ( ! empty( $_GET['tab'] ) ) echo esc_attr( $_GET['tab'] ) ?>" />
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
jQuery(function(){
|
||||
// Ajax Chosen Product Selectors
|
||||
jQuery("select.ajax_chosen_select_products").ajaxChosen({
|
||||
method: 'GET',
|
||||
url: '<?php echo admin_url('admin-ajax.php'); ?>',
|
||||
dataType: 'json',
|
||||
afterTypeDelay: 100,
|
||||
data: {
|
||||
action: 'woocommerce_json_search_products',
|
||||
security: '<?php echo wp_create_nonce("search-products"); ?>'
|
||||
}
|
||||
}, function (data) {
|
||||
var terms = {};
|
||||
|
||||
jQuery.each(data, function (i, val) {
|
||||
terms[i] = val;
|
||||
});
|
||||
return terms;
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</form>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</li>
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
|
@ -408,155 +344,6 @@ $customer_orders = $this->get_order_report_data( array(
|
|||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Output the product sales chart for single products.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function woocommerce_product_sales() {
|
||||
|
||||
global $wpdb, $woocommerce;
|
||||
|
||||
$chosen_product_ids = ( isset( $_POST['product_ids'] ) ) ? array_map( 'absint', (array) $_POST['product_ids'] ) : '';
|
||||
|
||||
if ( $chosen_product_ids && is_array( $chosen_product_ids ) ) {
|
||||
|
||||
$start_date = date( 'Ym', strtotime( '-12 MONTHS', current_time('timestamp') ) ) . '01';
|
||||
$end_date = date( 'Ymd', current_time( 'timestamp' ) );
|
||||
|
||||
$max_sales = $max_totals = 0;
|
||||
$product_sales = $product_totals = array();
|
||||
|
||||
// Get titles and ID's related to product
|
||||
$chosen_product_titles = array();
|
||||
$children_ids = array();
|
||||
|
||||
foreach ( $chosen_product_ids as $product_id ) {
|
||||
$children = (array) get_posts( 'post_parent=' . $product_id . '&fields=ids&post_status=any&numberposts=-1' );
|
||||
$children_ids = $children_ids + $children;
|
||||
$chosen_product_titles[] = get_the_title( $product_id );
|
||||
}
|
||||
|
||||
// Get order items
|
||||
$order_items = apply_filters( 'woocommerce_reports_product_sales_order_items', $wpdb->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 ];
|
||||
}
|
||||
}
|
||||
?>
|
||||
<h4><?php printf( __( 'Sales for %s:', 'woocommerce' ), implode( ', ', $chosen_product_titles ) ); ?></h4>
|
||||
<table class="bar_chart">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><?php _e( 'Month', 'woocommerce' ); ?></th>
|
||||
<th colspan="2"><?php _e( 'Sales', 'woocommerce' ); ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
if ( sizeof( $product_sales ) > 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=' . implode( ",", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ) );
|
||||
$orders_link = apply_filters( 'woocommerce_reports_order_link', $orders_link, $chosen_product_ids, $chosen_product_titles );
|
||||
|
||||
echo '<tr><th><a href="' . esc_url( $orders_link ) . '">' . date_i18n( 'F', strtotime( $date . '01' ) ) . '</a></th>
|
||||
<td width="1%"><span>' . esc_html( $sales ) . '</span><span class="alt">' . woocommerce_price( $product_totals[ $date ] ) . '</span></td>
|
||||
<td class="bars">
|
||||
<span style="width:' . esc_attr( $width ) . '%"> </span>
|
||||
<span class="alt" style="width:' . esc_attr( $width2 ) . '%"> </span>
|
||||
</td></tr>';
|
||||
}
|
||||
} else {
|
||||
echo '<tr><td colspan="3">' . __( 'No sales :(', 'woocommerce' ) . '</td></tr>';
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
<?php
|
||||
|
||||
} else {
|
||||
?>
|
||||
<form method="post" action="">
|
||||
<p><select id="product_ids" name="product_ids[]" class="ajax_chosen_select_products" multiple="multiple" data-placeholder="<?php _e( 'Search for a product…', 'woocommerce' ); ?>" style="width: 400px;"></select> <input type="submit" style="vertical-align: top;" class="button" value="<?php _e( 'Show', 'woocommerce' ); ?>" /></p>
|
||||
<script type="text/javascript">
|
||||
jQuery(function(){
|
||||
|
||||
// Ajax Chosen Product Selectors
|
||||
jQuery("select.ajax_chosen_select_products").ajaxChosen({
|
||||
method: 'GET',
|
||||
url: '<?php echo admin_url('admin-ajax.php'); ?>',
|
||||
dataType: 'json',
|
||||
afterTypeDelay: 100,
|
||||
data: {
|
||||
action: 'woocommerce_json_search_products',
|
||||
security: '<?php echo wp_create_nonce("search-products"); ?>'
|
||||
}
|
||||
}, function (data) {
|
||||
|
||||
var terms = {};
|
||||
|
||||
jQuery.each(data, function (i, val) {
|
||||
terms[i] = val;
|
||||
});
|
||||
|
||||
return terms;
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
</form>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Output the coupons overview stats.
|
||||
*
|
||||
|
|
|
@ -1,14 +1,19 @@
|
|||
<?php
|
||||
/**
|
||||
* WC_Report_Top_Sellers class
|
||||
* WC_Report_Sales_By_Product class
|
||||
*/
|
||||
class WC_Report_Top_Sellers extends WC_Admin_Report {
|
||||
class WC_Report_Sales_By_Product extends WC_Admin_Report {
|
||||
|
||||
public $product_ids = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->product_id = isset( $_GET['product_id'] ) ? absint( $_GET['product_id'] ) : '';
|
||||
if ( isset( $_GET['product_ids'] ) && is_array( $_GET['product_ids'] ) )
|
||||
$this->product_ids = array_map( 'absint', $_GET['product_ids'] );
|
||||
elseif ( isset( $_GET['product_ids'] ) )
|
||||
$this->product_ids = array( absint( $_GET['product_ids'] ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -16,7 +21,7 @@ class WC_Report_Top_Sellers extends WC_Admin_Report {
|
|||
* @return array
|
||||
*/
|
||||
public function get_chart_legend() {
|
||||
if ( ! $this->product_id )
|
||||
if ( ! $this->product_ids )
|
||||
return array();
|
||||
|
||||
$legend = array();
|
||||
|
@ -34,8 +39,8 @@ class WC_Report_Top_Sellers extends WC_Admin_Report {
|
|||
array(
|
||||
'type' => 'order_item_meta',
|
||||
'meta_key' => '_product_id',
|
||||
'meta_value' => $this->product_id,
|
||||
'operator' => '='
|
||||
'meta_value' => $this->product_ids,
|
||||
'operator' => 'IN'
|
||||
)
|
||||
),
|
||||
'query_type' => 'get_var',
|
||||
|
@ -54,8 +59,8 @@ class WC_Report_Top_Sellers extends WC_Admin_Report {
|
|||
array(
|
||||
'type' => 'order_item_meta',
|
||||
'meta_key' => '_product_id',
|
||||
'meta_value' => $this->product_id,
|
||||
'operator' => '='
|
||||
'meta_value' => $this->product_ids,
|
||||
'operator' => 'IN'
|
||||
)
|
||||
),
|
||||
'query_type' => 'get_var',
|
||||
|
@ -163,55 +168,177 @@ class WC_Report_Top_Sellers extends WC_Admin_Report {
|
|||
* @return array
|
||||
*/
|
||||
public function get_chart_widgets() {
|
||||
return array(
|
||||
array(
|
||||
'title' => __( 'Top Sellers', 'woocommerce' ),
|
||||
'callback' => array( $this, 'top_seller_widget' )
|
||||
)
|
||||
|
||||
$widgets = array();
|
||||
|
||||
if ( ! empty( $this->product_ids ) ) {
|
||||
$widgets[] = array(
|
||||
'title' => __( 'Showing reports for:', 'woocommerce' ),
|
||||
'callback' => array( $this, 'current_filters' )
|
||||
);
|
||||
}
|
||||
|
||||
$widgets[] = array(
|
||||
'title' => '',
|
||||
'callback' => array( $this, 'products_widget' )
|
||||
);
|
||||
|
||||
return $widgets;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the list of top sellers
|
||||
* Show current filters
|
||||
* @return void
|
||||
*/
|
||||
public function top_seller_widget() {
|
||||
?>
|
||||
<table cellspacing="0">
|
||||
<?php
|
||||
$top_sellers = $this->get_order_report_data( array(
|
||||
'data' => array(
|
||||
'_product_id' => array(
|
||||
'type' => 'order_item_meta',
|
||||
'order_item_type' => 'line_item',
|
||||
'function' => '',
|
||||
'name' => 'product_id'
|
||||
),
|
||||
'_qty' => array(
|
||||
'type' => 'order_item_meta',
|
||||
'order_item_type' => 'line_item',
|
||||
'function' => 'SUM',
|
||||
'name' => 'order_item_qty'
|
||||
)
|
||||
),
|
||||
'order_by' => 'order_item_qty DESC',
|
||||
'group_by' => 'product_id',
|
||||
'limit' => 10,
|
||||
'query_type' => 'get_results',
|
||||
'filter_range' => true
|
||||
) );
|
||||
public function current_filters() {
|
||||
$this->product_ids_titles = array();
|
||||
|
||||
if ( $top_sellers ) {
|
||||
foreach ( $top_sellers as $product ) {
|
||||
echo '<tr class="' . ( $this->product_id == $product->product_id ? 'active' : '' ) . '">
|
||||
<td class="count">' . $product->order_item_qty . '</td>
|
||||
<td class="name"><a href="' . add_query_arg( 'product_id', $product->product_id ) . '">' . get_the_title( $product->product_id ) . '</a></td>
|
||||
<td class="sparkline">' . $this->sales_sparkline( $product->product_id, 14, 'count' ) . '</td>
|
||||
</tr>';
|
||||
foreach ( $this->product_ids as $product_id ) {
|
||||
$this->product_ids_titles[] = get_the_title( $product_id );
|
||||
}
|
||||
|
||||
echo '<p>' . ' <strong>' . implode( ', ', $this->product_ids_titles ) . '</strong></p>';
|
||||
echo '<p><a class="button" href="' . remove_query_arg( 'product_ids' ) . '">' . __( 'Reset', 'woocommerce' ) . '</a></p>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Product selection
|
||||
* @return void
|
||||
*/
|
||||
public function products_widget() {
|
||||
?>
|
||||
<h4 class="section_title"><span><?php _e( 'Product Search', 'woocommerce' ); ?></span></h4>
|
||||
<div class="section">
|
||||
<form method="GET">
|
||||
<div>
|
||||
<select id="product_ids" name="product_ids[]" class="ajax_chosen_select_products" multiple="multiple" data-placeholder="<?php _e( 'Search for a product…', 'woocommerce' ); ?>"></select>
|
||||
<input type="submit" class="submit button" value="<?php _e( 'Show', 'woocommerce' ); ?>" />
|
||||
<input type="hidden" name="range" value="<?php if ( ! empty( $_GET['range'] ) ) echo esc_attr( $_GET['range'] ) ?>" />
|
||||
<input type="hidden" name="start_date" value="<?php if ( ! empty( $_GET['start_date'] ) ) echo esc_attr( $_GET['start_date'] ) ?>" />
|
||||
<input type="hidden" name="end_date" value="<?php if ( ! empty( $_GET['end_date'] ) ) echo esc_attr( $_GET['end_date'] ) ?>" />
|
||||
<input type="hidden" name="page" value="<?php if ( ! empty( $_GET['page'] ) ) echo esc_attr( $_GET['page'] ) ?>" />
|
||||
<input type="hidden" name="tab" value="<?php if ( ! empty( $_GET['tab'] ) ) echo esc_attr( $_GET['tab'] ) ?>" />
|
||||
<input type="hidden" name="report" value="<?php if ( ! empty( $_GET['report'] ) ) echo esc_attr( $_GET['report'] ) ?>" />
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
jQuery(function(){
|
||||
// Ajax Chosen Product Selectors
|
||||
jQuery("select.ajax_chosen_select_products").ajaxChosen({
|
||||
method: 'GET',
|
||||
url: '<?php echo admin_url('admin-ajax.php'); ?>',
|
||||
dataType: 'json',
|
||||
afterTypeDelay: 100,
|
||||
data: {
|
||||
action: 'woocommerce_json_search_products',
|
||||
security: '<?php echo wp_create_nonce("search-products"); ?>'
|
||||
}
|
||||
}, function (data) {
|
||||
var terms = {};
|
||||
|
||||
jQuery.each(data, function (i, val) {
|
||||
terms[i] = val;
|
||||
});
|
||||
return terms;
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</form>
|
||||
</div>
|
||||
<h4 class="section_title"><span><?php _e( 'Top Sellers', 'woocommerce' ); ?></span></h4>
|
||||
<div class="section">
|
||||
<table cellspacing="0">
|
||||
<?php
|
||||
$top_sellers = $this->get_order_report_data( array(
|
||||
'data' => array(
|
||||
'_product_id' => array(
|
||||
'type' => 'order_item_meta',
|
||||
'order_item_type' => 'line_item',
|
||||
'function' => '',
|
||||
'name' => 'product_id'
|
||||
),
|
||||
'_qty' => array(
|
||||
'type' => 'order_item_meta',
|
||||
'order_item_type' => 'line_item',
|
||||
'function' => 'SUM',
|
||||
'name' => 'order_item_qty'
|
||||
)
|
||||
),
|
||||
'order_by' => 'order_item_qty DESC',
|
||||
'group_by' => 'product_id',
|
||||
'limit' => 12,
|
||||
'query_type' => 'get_results',
|
||||
'filter_range' => true
|
||||
) );
|
||||
|
||||
if ( $top_sellers ) {
|
||||
foreach ( $top_sellers as $product ) {
|
||||
echo '<tr class="' . ( in_array( $product->product_id, $this->product_ids ) ? 'active' : '' ) . '">
|
||||
<td class="count">' . $product->order_item_qty . '</td>
|
||||
<td class="name"><a href="' . add_query_arg( 'product_ids', $product->product_id ) . '">' . get_the_title( $product->product_id ) . '</a></td>
|
||||
<td class="sparkline">' . $this->sales_sparkline( $product->product_id, 14, 'count' ) . '</td>
|
||||
</tr>';
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
?>
|
||||
</table>
|
||||
</div>
|
||||
<h4 class="section_title"><span><?php _e( 'Top Earners', 'woocommerce' ); ?></span></h4>
|
||||
<div class="section">
|
||||
<table cellspacing="0">
|
||||
<?php
|
||||
$top_earners = $this->get_order_report_data( array(
|
||||
'data' => array(
|
||||
'_product_id' => array(
|
||||
'type' => 'order_item_meta',
|
||||
'order_item_type' => 'line_item',
|
||||
'function' => '',
|
||||
'name' => 'product_id'
|
||||
),
|
||||
'_line_total' => array(
|
||||
'type' => 'order_item_meta',
|
||||
'order_item_type' => 'line_item',
|
||||
'function' => 'SUM',
|
||||
'name' => 'order_item_total'
|
||||
)
|
||||
),
|
||||
'order_by' => 'order_item_total DESC',
|
||||
'group_by' => 'product_id',
|
||||
'limit' => 12,
|
||||
'query_type' => 'get_results',
|
||||
'filter_range' => true
|
||||
) );
|
||||
|
||||
if ( $top_earners ) {
|
||||
foreach ( $top_earners as $product ) {
|
||||
echo '<tr class="' . ( in_array( $product->product_id, $this->product_ids ) ? 'active' : '' ) . '">
|
||||
<td class="count">' . woocommerce_price( $product->order_item_total ) . '</td>
|
||||
<td class="name"><a href="' . add_query_arg( 'product_ids', $product->product_id ) . '">' . get_the_title( $product->product_id ) . '</a></td>
|
||||
<td class="sparkline">' . $this->sales_sparkline( $product->product_id, 14, 'sales' ) . '</td>
|
||||
</tr>';
|
||||
}
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
jQuery('.section_title').click(function(){
|
||||
var next_section = jQuery(this).next('.section');
|
||||
|
||||
if ( jQuery(next_section).is(':visible') )
|
||||
return false;
|
||||
|
||||
jQuery('.section:visible').slideUp();
|
||||
jQuery('.section_title').removeClass('open');
|
||||
jQuery(this).addClass('open').next('.section').slideDown();
|
||||
|
||||
return false;
|
||||
});
|
||||
jQuery('.section').slideUp( 100, function() {
|
||||
<?php if ( empty( $this->product_ids ) ) : ?>
|
||||
jQuery('.section_title:eq(1)').click();
|
||||
<?php endif; ?>
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
|
@ -222,7 +349,7 @@ class WC_Report_Top_Sellers extends WC_Admin_Report {
|
|||
public function get_main_chart() {
|
||||
global $wp_locale;
|
||||
|
||||
if ( ! $this->product_id ) {
|
||||
if ( ! $this->product_ids ) {
|
||||
?>
|
||||
<div class="chart-container">
|
||||
<p class="chart-prompt"><?php _e( '← Choose a product to view stats', 'woocommerce' ); ?></p>
|
||||
|
@ -248,8 +375,8 @@ class WC_Report_Top_Sellers extends WC_Admin_Report {
|
|||
array(
|
||||
'type' => 'order_item_meta',
|
||||
'meta_key' => '_product_id',
|
||||
'meta_value' => $this->product_id,
|
||||
'operator' => '='
|
||||
'meta_value' => $this->product_ids,
|
||||
'operator' => 'IN'
|
||||
)
|
||||
),
|
||||
'group_by' => $this->group_by_query,
|
||||
|
@ -276,8 +403,8 @@ class WC_Report_Top_Sellers extends WC_Admin_Report {
|
|||
array(
|
||||
'type' => 'order_item_meta',
|
||||
'meta_key' => '_product_id',
|
||||
'meta_value' => $this->product_id,
|
||||
'operator' => '='
|
||||
'meta_value' => $this->product_ids,
|
||||
'operator' => 'IN'
|
||||
)
|
||||
),
|
||||
'group_by' => $this->group_by_query,
|
|
@ -1,66 +0,0 @@
|
|||
<?php
|
||||
|
||||
if ( ! class_exists( 'WC_Report_Top_Sellers' ) )
|
||||
include( 'class-wc-report-top-sellers.php' );
|
||||
/**
|
||||
* WC_Report_Top_Sellers class
|
||||
*/
|
||||
class WC_Report_Top_Earners extends WC_Report_Top_Sellers {
|
||||
|
||||
/**
|
||||
* [get_chart_widgets description]
|
||||
* @return array
|
||||
*/
|
||||
public function get_chart_widgets() {
|
||||
return array(
|
||||
array(
|
||||
'title' => __( 'Top Earners', 'woocommerce' ),
|
||||
'callback' => array( $this, 'top_earner_widget' )
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the list of top eaners
|
||||
* @return void
|
||||
*/
|
||||
public function top_earner_widget() {
|
||||
?>
|
||||
<table cellspacing="0">
|
||||
<?php
|
||||
$top_earners = $this->get_order_report_data( array(
|
||||
'data' => array(
|
||||
'_product_id' => array(
|
||||
'type' => 'order_item_meta',
|
||||
'order_item_type' => 'line_item',
|
||||
'function' => '',
|
||||
'name' => 'product_id'
|
||||
),
|
||||
'_line_total' => array(
|
||||
'type' => 'order_item_meta',
|
||||
'order_item_type' => 'line_item',
|
||||
'function' => 'SUM',
|
||||
'name' => 'order_item_total'
|
||||
)
|
||||
),
|
||||
'order_by' => 'order_item_total DESC',
|
||||
'group_by' => 'product_id',
|
||||
'limit' => 10,
|
||||
'query_type' => 'get_results',
|
||||
'filter_range' => true
|
||||
) );
|
||||
|
||||
if ( $top_earners ) {
|
||||
foreach ( $top_earners as $product ) {
|
||||
echo '<tr class="' . ( $this->product_id == $product->product_id ? 'active' : '' ) . '">
|
||||
<td class="count">' . woocommerce_price( $product->order_item_total ) . '</td>
|
||||
<td class="name"><a href="' . add_query_arg( 'product_id', $product->product_id ) . '">' . get_the_title( $product->product_id ) . '</a></td>
|
||||
<td class="sparkline">' . $this->sales_sparkline( $product->product_id, 14, 'sales' ) . '</td>
|
||||
</tr>';
|
||||
}
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
<?php
|
||||
}
|
||||
}
|
|
@ -15,11 +15,18 @@
|
|||
<?php _e( 'Custom:', 'woocommerce' ); ?>
|
||||
<form method="GET">
|
||||
<div>
|
||||
<?php
|
||||
// Maintain query string
|
||||
foreach ( $_GET as $key => $value )
|
||||
if ( is_array( $value ) )
|
||||
foreach ( $value as $v )
|
||||
echo '<input type="hidden" name="' . esc_attr( sanitize_text_field( $key ) ) . '[]" value="' . esc_attr( sanitize_text_field( $v ) ) . '" />';
|
||||
else
|
||||
echo '<input type="hidden" name="' . esc_attr( sanitize_text_field( $key ) ) . '" value="' . esc_attr( sanitize_text_field( $value ) ) . '" />';
|
||||
?>
|
||||
<input type="hidden" name="range" value="custom" />
|
||||
<input type="text" size="9" placeholder="yyyy-mm-dd" value="<?php if ( ! empty( $_GET['start_date'] ) ) echo esc_attr( $_GET['start_date'] ); ?>" name="start_date" class="range_datepicker from" />
|
||||
<input type="text" size="9" placeholder="yyyy-mm-dd" value="<?php if ( ! empty( $_GET['end_date'] ) ) echo esc_attr( $_GET['end_date'] ); ?>" name="end_date" class="range_datepicker to" />
|
||||
<input type="hidden" name="range" value="custom" />
|
||||
<input type="hidden" name="page" value="<?php if ( ! empty( $_GET['page'] ) ) echo esc_attr( $_GET['page'] ) ?>" />
|
||||
<input type="hidden" name="tab" value="<?php if ( ! empty( $_GET['tab'] ) ) echo esc_attr( $_GET['tab'] ) ?>" />
|
||||
<input type="submit" class="button" value="<?php _e( 'Go', 'woocommerce' ); ?>" />
|
||||
</div>
|
||||
</form>
|
||||
|
@ -38,7 +45,7 @@
|
|||
<ul class="chart-widgets">
|
||||
<?php foreach ( $this->get_chart_widgets() as $widget ) : ?>
|
||||
<li class="chart-widget">
|
||||
<h4><?php echo $widget['title']; ?></h4>
|
||||
<?php if ( $widget['title'] ) : ?><h4><?php echo $widget['title']; ?></h4><?php endif; ?>
|
||||
<?php call_user_func( $widget['callback'] ); ?>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -2654,11 +2654,32 @@ img.ui-datepicker-trigger { vertical-align: middle; margin-top: -1px; cursor: po
|
|||
-webkit-box-shadow: 0px 1px 2px rgba(0,0,0,.1);
|
||||
-moz-box-shadow: 0px 1px 2px rgba(0,0,0,.1);
|
||||
box-shadow: 0px 1px 2px rgba(0,0,0,.1);
|
||||
|
||||
&:after {
|
||||
content: ".";
|
||||
display: block;
|
||||
height: 0;
|
||||
clear: both;
|
||||
visibility: hidden;
|
||||
}
|
||||
h4 {
|
||||
background: #e5e5e5;
|
||||
border-bottom: 1px solid #d9d9d9;
|
||||
padding: 7px 10px 6px;
|
||||
margin:0;
|
||||
}
|
||||
.section_title {
|
||||
cursor: pointer;
|
||||
span {
|
||||
display: block;
|
||||
background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAFCAYAAACXU8ZrAAAAMElEQVQIW2OcOXPmfwYgSE9PZwTRyAAmB5bAphBZDK4bWRBdE4oVMEl067G6A919AJAYHtDVRR5EAAAAAElFTkSuQmCC) no-repeat right;
|
||||
}
|
||||
&.open {
|
||||
span {
|
||||
background-image: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
table {
|
||||
width: 100%;
|
||||
td {
|
||||
|
@ -2687,8 +2708,11 @@ img.ui-datepicker-trigger { vertical-align: middle; margin-top: -1px; cursor: po
|
|||
}
|
||||
}
|
||||
form, p {
|
||||
padding: 10px;
|
||||
margin:0;
|
||||
margin: 10px 0;
|
||||
padding: 0 10px;
|
||||
.submit {
|
||||
margin-top: 10px;
|
||||
}
|
||||
}
|
||||
#product_ids {
|
||||
width: 100%;
|
||||
|
@ -2734,6 +2758,7 @@ img.ui-datepicker-trigger { vertical-align: middle; margin-top: -1px; cursor: po
|
|||
}
|
||||
.chart-prompt {
|
||||
line-height: 650px;
|
||||
margin: 0;
|
||||
color: #999;
|
||||
font-size: 1.2em;
|
||||
font-style: italic;
|
||||
|
|
Loading…
Reference in New Issue