Understanding: global $post
The WordPress global variable $post
, contains the data of the current post
within the The Loop
. WordPress will assign a value to this variable in each loop iteration. If you’re trying to access $post
from outside the WP loop, it will be null
or ""
.
You should be able to use the following instead;
$page_id = get_queried_object_id();
So your code would look something like this;
// 3. ADD COLOR TO IN PROGRESS BUTTON
add_action('admin_head', 'styling_packed_order_list' );
function styling_packed_order_list() {
global $pagenow;
$page_id = get_queried_object_id();
if( $pagenow != 'edit.php') return; // Exit
if( get_post_type($page_id) != 'shop_order' ) return; // Exit
// HERE below set your custom status
$order_status="packed"; // <==== HERE
?>
<style>
.order-status.status-<?php echo sanitize_title( $order_status ); ?> {
background: #0D98BA;
color: #ffffff;
}
</style>
<?php
}