Call WooCommerce filter "manage_edit-shop_order_columns", to add a new column and action "manage_shop_order_posts_custom_column", to add content in to the new column.
The code should be added in the function.php file of the child theme.
<?php | |
/** | |
* Use in function.php of the child theme. | |
* Call WooCommerce filter "manage_edit-shop_order_columns" to add a new column. | |
* Change the order of others to add new one in the right place. | |
*/ | |
add_filter('manage_edit-shop_order_columns', 'add_warning_column', 10); | |
function add_warning_column($columns) | |
{ | |
// Take current state of column order_status | |
$order_status = $columns['order_status']; | |
unset($columns['order_status']); // remove column from table | |
// Take current state of column order_total | |
$order_total = $columns['order_total']; | |
unset($columns['order_total']); // remove column from table | |
// Add columns in the correct order | |
$columns['order_status'] = $order_status; | |
$columns['order_error'] = "Status Info"; | |
$columns['order_total'] = $order_total; | |
return $columns; | |
} | |
/** | |
* Call WooCommerce action "manage_shop_order_posts_custom_column" to add content in to the new column. | |
* FYI: The content is exemplary and should be rewritten with the business logic that will be used. | |
*/ | |
add_action('manage_shop_order_posts_custom_column', 'update_order_status_if_error'); | |
function update_order_status_if_error($colname) | |
{ | |
global $the_order; | |
// check if the new column is on the way | |
if ($colname === 'order_error') { | |
$order_status = $the_order->get_status(); | |
// add content to the column | |
if ($order_status === "failed") { | |
echo '<mark style="background:red;color:white" class="order-status tips"><span>Error</span></mark>'; | |
} else { | |
echo '<mark style="background:green;color:white" class="order-status tips"><span>OK</span></mark>'; | |
} | |
} | |
} |