【发布时间】:2021-04-25 01:15:19
【问题描述】:
所以我想计算我的网站的总销售额(不含税)。但是,我在网站上有大量订单。使其崩溃页面,因为它无法处理计算。有没有更好的方法来从 WooCommerce 计算/检索这个?
function calculateTotalSales(){
$orders = get_posts( array(
'numberposts' => - 1,
'post_type' => array( 'shop_order' ),
'post_status' => array( 'wc-completed', 'wc-processing', 'wc-pending' )
) );
$total = 0;
foreach ( $orders as $customer_order ) {
$order = wc_get_order( $customer_order );
$total += $order->get_total() - $order->get_total_tax();
}
update_option('totalSales', $totalSales);
return $totalSales;
}
【问题讨论】:
-
你检查过报告部分吗?
标签: php sql wordpress woocommerce orders