Woocommerce 3.3 管理订单列表中的自定义订单状态背景按钮颜色
在新的 woo 订单屏幕中,旧的颜色状态图标现在消失了,取而代之的是带有彩色背景的大状态按钮.
With the new woo orders screen, the old color status icons are now gone and replaced with a large status button with a colored background.
正在处理为绿色,已完成为蓝色,已取消为灰色等.
Processing is green, Completed is blue, Cancelled is grey etc.
我在 woocommerce 订单中有一个自定义订单状态,称为:进行中.自定义订单状态似乎也只是默认的灰色背景.我想为我的自定义订单状态分配一个颜色背景.我试图找到一个代码片段来做到这一点,但没有运气.
I have a custom order status in woocommerce orders called: In Progress. Custom order statuses seem to also be given just a default grey color background. I would like to assign a color background to my custom order status. I have tried to find a code snippet in order to do this, but have had no luck.
您可以通过这种方式为管理订单列表中显示的自定义订单状态设置 CSS 颜色和背景颜色:
You can set CSS color and background color to your custom order status displayed in admin order list this way:
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 文件中.经测试有效.
Code goes in function.php file of your active child theme (or active theme). Tested and works.