简体   繁体   English

在Woocommerce订单销售报告中包括自定义订单状态

[英]Include Custom Order Status in Woocommerce Orders sales reports

I have a custom order status - In Progress. 我有一个自定义订单状态-进行中。 The code I have for it is below. 我的代码如下。 It works great - but the orders with this custom order status are not being included in the standard Woo Sales Reports or the Woocommerce Status Dashboard Widget. 效果很好-但是具有此自定义订单状态的订单未包含在标准的Woo销售报告或Woocommerce状态仪表板小部件中。

Could someone please help me out and take a look and see how I can add to this snippet below so that the $ from this custom order status 'In Progress' are reflected in the Woo Sales Report $. 有人可以帮我一下,看看如何将其添加到下面的代码段中,以便此自定义订单状态为“进行中”的$反映在Woo销售报告$中。

// 1 New order status AFTER woo 2.2 IN PROGRESS
add_action( 'init', 'register_my_new_order_statuses' );
function register_my_new_order_statuses() {
    register_post_status( 'wc-in-progress', array(
        'label'                     => _x( 'In Progress', 'Order status', 'woocommerce' ),
        'public'                    => true,
        'exclude_from_search'       => false,
        'show_in_admin_all_list'    => true,
        'show_in_admin_status_list' => true,
        'label_count'               => _n_noop( 'In Progress <span class="count">(%s)</span>', 'In Progress<span class="count">(%s)</span>', 'woocommerce' )
    ) );
}
add_filter( 'wc_order_statuses', 'my_new_wc_order_statuses' );
// Register in wc_order_statuses.
function my_new_wc_order_statuses( $order_statuses ) {
    $order_statuses['wc-in-progress'] = _x( 'In Progress', 'Order status', 'woocommerce' );
    return $order_statuses;
}

/*
 * 2 CHANGE STATUSES ORDER IN DROPDOWN LIST
 * @param array $wc_statuses_arr Array of all order statuses on the website
 */
function change_statuses_order( $wc_statuses_arr ){

    $new_statuses_arr = array(
        'wc-processing' => $wc_statuses_arr['wc-processing'], // 1
        'wc-in-progress' => $wc_statuses_arr['wc-in-progress'], // 2      
        'wc-completed' => $wc_statuses_arr['wc-completed'], // 3
        'wc-cancelled' => $wc_statuses_arr['wc-cancelled'], // 4
        'wc-refunded' => $wc_statuses_arr['wc-refunded'], // 5
        'wc-failed' => $wc_statuses_arr['wc-failed'], // 6
        'wc-pending' => $wc_statuses_arr['wc-pending'], // 7
        'wc-on-hold' => $wc_statuses_arr['wc-on-hold'] // 8
    );

    return $new_statuses_arr;
}

add_filter( 'wc_order_statuses', 'change_statuses_order' );

/** 3 ADD COLOR TO IN PROGRESS BUTTON **/

add_action('admin_head', 'styling_admin_order_list' );
function styling_admin_order_list() {
    global $pagenow;
    if( $_GET['post_type'] == 'shop_order' && $pagenow == 'edit.php'):

    // HERE below set your custom status
    $order_status = 'In Progress'; // <==== HERE
    ?>
    <style>
        .order-status.status-<?php echo sanitize_title( $order_status ); ?> {
            background: #cc0099;
            color: #ffffff;
        }
    </style>
    <?php
    endif;
}

You can use the following hooked function, that will add your "custom status" to Orders reports: 您可以使用以下挂钩函数,该函数会将“自定义状态”添加到“订单”报告中:

add_filter( 'woocommerce_reports_order_statuses', 'include_custom_order_status_to_reports', 20, 1 );
function include_custom_order_status_to_reports( $statuses ){
    // Adding the custom order status to the 3 default woocommerce order statuses
    return array( 'processing', 'in-progress', 'completed', 'on-hold' );
}

Code goes in function.php file of your active child theme (or active theme). Tested and works. 经过测试和工作。


There is a generated error in your 3rd function related to $_GET['post_type'] == 'shop_order' … Instead you can chnage it this way: 在您的第三个函数中,有一个与$_GET['post_type'] == 'shop_order' …您可以通过以下方式更改它:

// 3. ADD COLOR TO IN PROGRESS BUTTON
add_action('admin_head', 'styling_admin_order_list' );
function styling_admin_order_list() {
    global $pagenow, $post;

    if( $pagenow != 'edit.php') return; // Exit
    if( get_post_type($post->ID) != 'shop_order' ) return; // Exit

    // HERE below set your custom status
    $order_status = 'In Progress'; // <==== HERE
    ?>
    <style>
        .order-status.status-<?php echo sanitize_title( $order_status ); ?> {
            background: #cc0099;
            color: #ffffff;
        }
    </style>
    <?php
}

It will avoid this small error as post_type is not in the URL of order edit pages (I know is my fault as this was the code of one of my answers) 它将避免这种小错误,因为post_type不在订单编辑页面的URL中(我知道是我的错,因为这是我的答案之一)

暂无
暂无

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

相关问题 "为具有自定义状态的订单禁用 WooCommerce 订单电子邮件通知" - Disable WooCommerce order email notification for orders with custom status WooCommerce自定义报告:获取状态为已完成的订单 - WooCommerce custom report: Get orders with completed status 为Woocommerce管理员订单添加自定义订单状态的特定操作按钮图标 - Add specific action button icon for custom order status to Woocommerce admin orders 自定义 PHP 剪辑器,用于向管理员发送电子邮件通知,以了解 WooCommerce 中的待处理订单状态,导致已处理订单的电子邮件重复 - Custom PHP snipper for email notification to the admin for pending order status in WooCommerce causing duplicated emails for processed orders 在 Woocommerce 管理订单列表中显示具有“全部”自定义状态的订单 - Display orders with a custom status for “all” in Woocommerce admin orders list 在 WooCommerce 订单中显示 ACF 订单自定义字段 - Display ACF order custom field in WooCommerce orders 在WooCommerce管理订单页面的状态下拉菜单中隐藏订单状态 - Hide order status in the status dropdown on WooCommerce admin orders page 在woocommerce中设置自定义订单状态 - setting custom order status in woocommerce 如何在免费订单上禁用自动将订单状态设置为“进行中”(Woocommerce) - How to disable automatically set order status to 'Progressing' on Free Orders (Woocommerce) 自动更改 WooCommerce 中“预购”的订单状态 - Automatically change order status for "pre-orders" in WooCommerce
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM