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.
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 :/