我正在寻找一种方法,以突出显示的行政命令列表行的基础上,以支付方式。(特别是货到付款-现金交付)
基于Highlight Woocommerce admin orders list when order contains a regular product anwser代码,我编写了以下代码:
function add_custom_class( $classes, $class, $post_id ){
// Check current screen and make sure you are only doing in order list page.
$currentScreen = get_current_screen();
if( $currentScreen->id === "edit-shop_order" ) {
// Get an instance of the WC_Order object
$order = wc_get_order( $order_id );
$has_cod = false;
// Set Payment Gateway ID
foreach ( $orders as $order){
if ( $order->get_payment_method() === 'cod' ) {
$has_cod = true;
break;
}
}
if( $has_cod ) {
$classes[] = 'order-has-cod';
}
}
return $classes;
}
add_filter( 'post_class', 'add_custom_class', 10, 3 );
function add_custom_admin_css(){
$currentScreen = get_current_screen();
if( $currentScreen->id === "edit-shop_order" ) {
?>
<style type="text/css">
.order-has-cod{
background-color: #a8fff6 !important; // here you have to your own color
}
</style>
<?php
}
}
add_action( 'admin_head', 'add_custom_admin_css', 10, 1 );
很不幸没有达到预期的结果。有什么建议吗?
1条答案
按热度按时间cyej8jka1#
您的代码尝试包含一些错误:
$order = wc_get_order( $order_id )
时$order_id
未定义,应将$order_id
替换为$post_id
$orders
未定义foreach()
参数必须为数组类型|对象,给定空值因此,您将获得: