I've been trying to add CSS to woocommerce order statuses. The first method was to rename the order statuses with a function and add HTML tags to each one.
This solution works for the frontend (my account -> orders), but creates display issues in the backend:
add_filter( 'wc_order_statuses', 'ts_rename_order_status_msg', 20, 1 );
function ts_rename_order_status_msg( $order_statuses ) {
$order_statuses['wc-completed'] = _x( '<div class="label success">Purchuased</div>', 'Order status', 'woocommerce' );
$order_statuses['wc-processing'] = _x( 'Processing', 'Order status', 'woocommerce' );
$order_statuses['wc-on-hold'] = _x( 'Waiting', 'Order status', 'woocommerce' );
$order_statuses['wc-pending'] = _x( 'Deleted', 'Order status', 'woocommerce' );
return $order_statuses;
}
So I went looking for a different solution and came across this post from LoicTheAztec: Custom order status background button color in Woocommerce 3.3 admin order list
The solution works for the backend and I was wondering if the same could be done for the frontend (my account > orders). So I tried to do something like this.
add_action('admin_head', 'styling_admin_order_list' ); // Here I don't know what to replace
function styling_admin_order_list() {
global $pagenow, $post; Here I don't know what to replace
if( $pagenow != 'my-orders-page') return; // Exit
if( get_post_type($post->ID) != 'ID_my-orders-page' ) return; // Exit
// HERE we set your custom status
$order_status_completed = 'Completed'; // <==== HERE
?>
<style>
.order-status.status-<?php echo sanitize_title( $order_status_completed ); ?> {
background: #d7f8a7;
color: #0c942b;
}
</style>
<?php
}
Unfortunately without the desired result, any advice?

所有评论(0)