welcartのダッシュボードに毎月の売り上げを表示する

welcart

これ、以前からやりたかった事です
感謝

functions.phpに以下を追加するだけ

/////////////////////// 受注金額リスト /////////////////////// 

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 
}

質問やご指摘など気軽にどうぞ

コメントを投稿する

CAPTCHA