Copilot
I searched the web for some possible solutions to your problem. Here are some of the results that I found:
- Stack Overflow: This is a question posted by another user who has the same issue as you. They are trying to add a custom column and display the order meta data in the WooCommerce admin orders list. There are two answers that suggest different ways to achieve this. One answer uses the
woocommerce_admin_order_data_after_order_details
hook and the other uses the woocommerce_admin_order_preview_get_order_details
hook. You can try these solutions and see if they work for you.
- Webroom Tech: This is a tutorial on how to add a custom column and display order meta data in the WooCommerce admin orders list. It shows how to use the
manage_edit-shop_order_columns
filter and the manage_shop_order_posts_custom_column
action to create and populate the column. It also provides some examples of how to display different types of order meta data, such as billing phone and private notes. You can follow this tutorial and modify the code according to your needs.
- Admin Columns: This is a WordPress plugin that allows you to create and manage custom columns for any post type, including WooCommerce orders. You can use this plugin to easily add and display order meta data in the order table without writing any code. You can also sort, filter, and export the columns. You can install this plugin from the WordPress plugin directory or from the plugin’s website.
Chat GPT
It looks like there are a couple of issues in your code. Here are some corrections:
- In the
add_meeting_points_column
function, the array key should be ‘meeting_points’ (lowercase), not ‘Meeting_Points’.
- In the
display_Meeting_Points_column
function, the argument in the wc_get_order_meta_keys
function should be the order object, not the order keys. Also, ensure that the meta key used matches the one you have stored in your orders.
Here’s the corrected code:
add_filter('manage_edit-shop_order_columns', 'add_meeting_points_column');
function add_meeting_points_column($columns) {
$columns = array_merge(
array_slice($columns, 0, array_search('order_date', array_keys($columns)), true),
array('meeting_points' => __('Meeting Points', 'text-domain')),
array_slice($columns, array_search('order_date', array_keys($columns)), null, true)
);
return $columns;
}
add_action('manage_shop_order_posts_custom_column', 'display_meeting_points_column', 20, 2);
function display_meeting_points_column($column, $post_id) {
if ('meeting_points' === $column) {
$order = wc_get_order($post_id);
if ($order) {
$meeting_points = $order->get_meta('MeetingPoints'); // Use the correct meta key
echo !empty($meeting_points) ? esc_html($meeting_points) : esc_html__('Not Available', 'text-domain');
}
}
}
Make sure that ‘MeetingPoints’ is the correct meta key you used when saving the meeting points for the order. Adjust the meta key if needed.