[英]Highlight WooCommerce admin orders list based on order shipping method
I'm looking for a way to highlight the admin order list line based on the order shipping method.我正在寻找一种方法来根据订单发货方式突出显示管理订单列表行。 (specifically for local pickup) (专供本地取件)
Based on Highlight WooCommerce admin orders list based on order payment method anwser code, I have changed $payment_method for $shipping_method and.type-shop_order.cod for.type-shop_order.local_pickupcode for shipping methods but it did nothing in admin panel I have also tried using shipping method title instead of $shipping_method, but it did nothing.基于Highlight WooCommerce admin orders list based on order payment method anwser code,我改变了 $payment_method 为 $shipping_method 和 .type-shop_order.cod 为 .type-shop_order.local_pickupcode 运输方式,但它在管理面板中什么也没做我也有尝试使用运输方法标题而不是 $shipping_method,但它什么也没做。
i have also tried to get all classes with我也试过让所有的班级都有
public function get_shipping_classes() {
if ( empty( $this->shipping_classes ) ) {
$classes = get_terms(
'product_shipping_class',
array(
'hide_empty' => '0',
'orderby' => 'name',
)
);
$this->shipping_classes = ! is_wp_error( $classes ) ? $classes : array();
}
return apply_filters( 'woocommerce_get_shipping_classes', $this->shipping_classes );
}
but it hid all orders except local pickup.但它隐藏了除本地取货外的所有订单。
Here is the code:这是代码:
function filter_post_class( $classes, $class, $post_id ) {
// Determines whether the current request is for an administrative interface page
if ( ! is_admin() ) return $classes;
// Get the current screen object
$current_screen = get_current_screen();
// Only when
if ( $current_screen->id === 'edit-shop_order' ) {
// Get an instance of the WC_Order object
$order = wc_get_order( $post_id );
// Is a WC_Order
if ( is_a( $order, 'WC_Order' ) ) {
// Get the payment method
$shipping_method = $order->get_shipping_method();
//NOT empty
if ( ! empty( $shipping_method ) ) {
$classes[] = $shipping_method;
}
}
}
// Return the array
return $classes;
}
add_filter( 'post_class', 'filter_post_class', 10, 3 );
// Add CSS
function action_admin_head() {
// Get the current screen object
$current_screen = get_current_screen();
// Only when
if ( $current_screen->id === 'edit-shop_order' ) {
echo '<style>
.type-shop_order.local_pickup {
background-color: #e9a5a5 !important;
}
</style>';
}
}
add_action( 'admin_head', 'action_admin_head' );
Any advice how to change it please?有什么建议如何改变吗? i am not php coder so this is kinda google try thing for me:/我不是 php 编码员所以这有点像谷歌对我的尝试:/
i have made it thanks to CBroe.感谢 CBroe,我做到了。
function filter_post_class( $classes, $class, $post_id ) {
// Determines whether the current request is for an administrative interface page
if ( ! is_admin() ) return $classes;
// Get the current screen object
$current_screen = get_current_screen();
// Only when
if ( $current_screen->id === 'edit-shop_order' ) {
// Get an instance of the WC_Order object
$order = wc_get_order( $post_id );
// Is a WC_Order
if ( is_a( $order, 'WC_Order' ) ) {
// Get the shipping method
$shipping_method = @array_shift($order->get_shipping_methods());
$shipping_method_id = $shipping_method['method_id'];
//NOT empty
if ( ! empty( $shipping_method ) ) {
$classes[] = $shipping_method_id;
}
}
}
// Return the array
return $classes;
}
add_filter( 'post_class', 'filter_post_class', 10, 3 );
// Add CSS
function action_admin_head() {
// Get the current screen object
$current_screen = get_current_screen();
// Only when
if ( $current_screen->id === 'edit-shop_order' ) {
echo '<style>
.type-shop_order.local_pickup {
background-color: #e9a5a5 !important;
}
</style>';
}
}
add_action( 'admin_head', 'action_admin_head' );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.