WooCommerce Custom Order Columns
January 30, 2025 ยท AI Conversations
User
manage_edit-shop_order_columns
Assistant
It looks like you're referring to modifying the columns in the WooCommerce admin orders list using the `manage_edit-shop_order_columns` filter. This filter allows you to customize the columns displayed in the **WooCommerce Orders** admin page.
### **Example: Add a Custom Column**
You can add a new column (e.g., "Order Source") by using the following code:
// Add custom column to orders list
add_filter('manage_edit-shop_order_columns', function ($columns) {
$columns['order_source'] = __('Order Source', 'your-textdomain');
return $columns;
});
// Populate the custom column with data
add_action('manage_shop_order_posts_custom_column', function ($column, $post_id) {
if ($column === 'order_source') {
$order = wc_get_order($post_id);
echo get_post_meta($post_id, '_order_source', true) ?: 'N/A';
}
}, 10, 2);
### **Explanation:**
1. **`manage_edit-shop_order_columns`**: Adds a new column labeled **Order Source**.
2. **`manage_shop_order_posts_custom_column`**: Fills the column with custom meta data (`_order_source`).
#### **Removing an Existing Column**
To remove unwanted columns, modify the `$columns` array:
add_filter('manage_edit-shop_order_columns', function ($columns) {
unset($columns['order_actions']); // Removes the actions column
return $columns;
});
Let me know if you need specific modifications! ๐