Using a WooCommerce site we sell electronic parts and offer free next-day delivery as standard, but also next day pre 10 and Saturday morning deliveries as a paid upgrade. As these are the exceptions rather than the rule in our orders, I miss them. I’ve tried adding ***** and other such characters to the description but they just dont stand out enough to make me notice them. I therefore want to change the background color in the order table based on the shipping method, so I do not upset customers.
I found this (which as far as I can tell uses “local pickup” but need to make it based on $shipping_method_id = 3,5,13
Anyone able to help ?
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' );
Jason Ryan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.