douceng7070 2018-03-31 23:01
浏览 173
已采纳

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

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.

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 $.

// 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;
}
  • 写回答

1条回答 默认 最新

  • dqypcghd381390 2018-04-01 00:04
    关注

    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:

    // 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)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?