繁体   English   中英

如何在Woocommerce报表中添加“按邮政编码销售”

[英]How to add “Sales by postal code” to Woocommerce reports

我已将以下代码添加到functions.php中,以向Woocommerce销售报告中添加“按邮政编码销售”标签:

function filter_woocommerce_admin_reports( $reports ) { 

$array = array(
    'salse_by_post_code' => array(
        'title' => 'Sales by postal code',
        'description' => '',
        'hide_title' => 1,
        'callback' => 'callback_postal_code'
    )
);

$reports['orders']['reports'] = array_merge($reports['orders']['reports'],$array);

return $reports; 
}

add_filter( 'woocommerce_admin_reports', 'filter_woocommerce_admin_reports', 10, 1 ); 

function callback_postal_code() {
    echo "Add Your Code here";
}

代替“函数callback_postal_code”中的echo功能,我需要此脚本来过滤用于下订单的实际邮政编码并相应地显示它们。

我正在寻找正确的触发器来完成此功能。 我还没有找到它。 有什么建议吗?

您可以如下创建自定义函数:

function my_custom_get_total_sales() {

global $wpdb;

$order_totals = apply_filters( 'woocommerce_reports_sales_overview_order_totals', $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

WHERE meta.meta_key = '_order_total'

AND posts.post_type = 'shop_order'

AND posts._shipping_postcode='<your Shipping Code>'

AND posts.post_status IN ( '" . implode( "','", array( 'wc-completed', 'wc-processing', 'wc-on-hold' ) ) . "' )

" ) );

return absint( $order_totals->total_sales);

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM