Ecommerce Shopify WordPress Discussion

WooCommerce Admin Order list Custom Column doesn't display values

I have "How Did You Discover Us?" info that is obtained during checkout to be included in my custom Info column within the admin orders' page in WooCommerce. I have the same detail displayed in edit order page. However, it isn't returning How Did You Discover Us? value in the new Info column in admin orders. It remains empty. How can I get it to display correctly? //Checkout Section add_filter('woocommerce_checkout_fields', function($fields) { $fields['billing']['billing_my_custom_select'] = [ 'label' => __('How Did You Discover Us?', 'textdomain'), 'required' => true, 'type' => 'select', 'options' => [ '' => __('Select Source', 'textdomain'), 'X' => __('X', 'textdomain'), 'Y' => __('Y', 'textdomain') ], 'class' => ['form-row-wide'], 'priority' => 110 ]; return $fields; }); //Admin Note Section add_action('woocommerce_admin_order_data_after_billing_address', function($order) { $my_value = get_post_meta($order->id, '_billing_my_custom_select', true); if (!empty($my_value)) { echo '<p><strong>' . __('How Did You Discover Us?', 'textdomain') . ':</strong> ' . $my_value . '</p>'; } }); //End How Did You Discover Us //Edit Admin Orders Page, New Column add_filter('manage_edit-shop_order_columns', 'add_order_new_column_header', 20); function add_order_new_column_header($columns){ $new_columns = array(); foreach ($columns as $column_name => $column_info){ $new_columns[$column_name] = $column_info; if ('order_total' === $column_name) { $new_columns['order_details'] = __('Info', 'textdomain'); } } return $new_columns; } add_action('manage_shop_order_posts_custom_column', 'add_wc_order_admin_list_column_content'); function add_wc_order_admin_list_column_content($column){ global $post; if ('order_details' === $column){ $order = wc_get_order( $post->ID, '_billing_my_custom_select', 1); echo $my_value; } } //End Edit Admin Orders Page, New Column
Your code is a bit outdated since WooCommerce 3 and there are some mistakes. Also, you should always use explicit meta keys and always name the hooked functions. Try the following code replacement: // Add custom Checkout billing field add_filter('woocommerce_checkout_fields', 'add_custom_checkout_field' ); function add_custom_checkout_field($fields) { $fields['billing']['billing_discover_us'] = [ 'label' => __('How Did You Discover Us?', 'textdomain'), 'required' => true, 'type' => 'select', 'options' => [ '' => __('Select Source', 'textdomain'), 'X' => __('X', 'textdomain'), 'Y' => __('Y', 'textdomain') ], 'class' => ['form-row-wide'], 'priority' => 110 ]; return $fields; } // Display Admin order custom Checkout billing field value add_action('woocommerce_admin_order_data_after_billing_address', 'display_admin_order_custom_field_value' ); function display_admin_order_custom_field_value( $order ) { if ( $value = $order->get_meta('_billing_discover_us') ) { echo '<p><strong>' . __('How Did You Discover Us?', 'textdomain') . ':</strong> ' . $value . '</p>'; } } // Admin Orders list: New Column add_filter( 'manage_edit-shop_order_columns', 'add_order_new_column_header', 20 ); function add_order_new_column_header( $columns ){ $new_columns = array(); foreach ($columns as $column_name => $column_info){ $new_columns[$column_name] = $column_info; if ( 'order_total' === $column_name ) { $new_columns['order_details'] = __('Info', 'textdomain'); } } return $new_columns; } // Admin Orders list: New Column content add_action( 'manage_shop_order_posts_custom_column', 'add_wc_order_admin_list_column_content', 20 ); function add_wc_order_admin_list_column_content( $column ){ if ( 'order_details' === $column ){ global $the_order; echo $the_order->get_meta('_billing_discover_us'); } } Code goes in functions.php file of your child theme (or in a plugin). Tested and works. Note: As I have renamed your custom field meta key, you will need to place an order to see the changes. You will get something like: Related: How to get WooCommerce order details

January 27, 2024

TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.