Woocommerce 3.3 管理订单列表中的自定义订单状态背景按钮颜色

Custom order status background button color in Woocommerce 3.3 admin order list

在新的 woo 订单屏幕中,旧的彩色状态图标现已消失,取而代之的是带有彩色背景的大状态按钮。

处理中为绿色,已完成为蓝色,已取消为灰色等

我在 woocommerce 订单中有一个自定义订单状态,名为:进行中。自定义订单状态似乎也只提供默认的灰色背景。我想为我的自定义订单状态分配颜色背景。我试图找到一个代码片段来执行此操作,但没有成功。

您可以通过以下方式将 CSS 颜色和背景颜色设置为显示在管理订单列表中的自定义订单状态:

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 we set your custom status
    $order_status = 'Dispatched'; // <==== HERE
    ?>
    <style>
        .order-status.status-<?php echo sanitize_title( $order_status ); ?> {
            background: #d7f8a7;
            color: #0c942b;
        }
    </style>
    <?php
}

代码进入您的活动子主题(或活动主题)的 function.php 文件。已测试并有效。