ちゃんとcsvダウンロードして、手元で売上げやら何やら管理してれば割とどうでも良いかもですが…、やっぱりウェブ上でも見れた方が良いよね! …というときに。
以下の関数をfunctions.phpに記述します。アンチョコはusceshop.class.php より、get_order_num() & get_order_amount() の両関数。usces_action_admintop_box2にフックしています。「受注数・金額」と「商品登録情報」の間に表示したい場合は、usces_action_admintop_box1にフックして下さいな。
(言うまでもありませんが、画像の数字はダミーです。)
code: transition of amount of 12 months
/////////////////////// 受注金額リスト ///////////////////////
add_action( 'usces_action_admintop_box2', 'amount_of_12_months', 10 );
function amount_of_12_months (){
global $wpdb;
$datestr = substr(get_date_from_gmt(gmdate('Y-m-d H:i:s', time())), 0, 10);
$yearstr = substr($datestr, 0, 4);
$monthstr = substr($datestr, 5, 2);
$daystr = substr($datestr, 8, 2);
?>
<h4>過去の受注数・金額</h4>
<div class="usces_box">
<table class="dashboard">
<tr>
<th><?php _e('Currency','usces'); ?> : <?php usces_crcode(); ?></th><th><?php _e('number of order', 'usces'); ?></th><th><?php _e('amount of order', 'usces'); ?></th>
</tr>
<?php
for ($num = 0; $num < 12; $num++){
$date = date('Y年n月', mktime(0, 0, 0, (int)$monthstr+$num, 1, (int)$yearstr-1));
$startdate = date('Y-m-01 00:00:00', mktime(0, 0, 0, (int)$monthstr+$num, 1, (int)$yearstr-1));
$enddate = date('Y-m-d 23:59:59', mktime(0, 0, 0, (int)$monthstr+1+$num, 0, (int)$yearstr-1));
$table_name = $wpdb->prefix . 'usces_order';
$query = $wpdb->prepare("SELECT COUNT(ID) AS ct FROM $table_name WHERE order_date >= %s AND order_date <= %s AND 0 = LOCATE(%s, order_status) AND 0 = LOCATE(%s, order_status)", $startdate, $enddate, 'cancel', 'estimate');
$number = $wpdb->get_var($query);
$query = $wpdb->prepare("SELECT SUM(order_item_total_price) AS price, SUM(order_usedpoint) AS point, SUM(order_discount) AS discount, SUM(order_shipping_charge) AS shipping, SUM(order_cod_fee) AS cod, SUM(order_tax) AS tax
FROM $table_name WHERE order_date >= %s AND order_date <= %s AND 0 = LOCATE(%s, order_status) AND 0 = LOCATE(%s, order_status)", $startdate, $enddate, 'cancel', 'estimate');
$res = $wpdb->get_row($query, ARRAY_A);
if( $res !== NULL ){
$amount = $res['price'] - $res['point'] + $res['discount'] + $res['shipping'] + $res['cod'] + $res['tax'];
echo '<tr><td>'.$date.' : </td><td class="bignum">' .number_format($number). '</td><td class="bignum">'.usces_crform( $amount, true, false, 'return' ). '</td></tr>'."n";
}
}
?>
</table>
</div>
<?php
}