Custom Order Column Not Showing After Enabling HPOS
-
Hi everyone,
I’m trying to add a custom column to the WooCommerce Orders page that displays the total number of orders made by each customer based on their billing email address. Before switching to HPOS (High-Performance Order Storage), the code worked perfectly, and the custom column was displayed correctly. However, after enabling HPOS, the column is no longer visible in the Orders table, nor does it appear in the Screen Options.` WordPress Environment
WordPress address (URL):
Site address (URL):
WC Version: 9.3.3
Legacy REST API Package Version: Il plugin API REST legacy non è installato in questo sito.
Action Scheduler Version: ? 3.8.2
Log Directory Writable: ?
WP Version: 6.6.2
WP Multisite: –
WP Memory Limit: 512 MB
WP Debug Mode: ?
WP Cron: –
Language: it_IT
External object cache: ? Server EnvironmentCode Used:
Below is the code I’m using to add the custom column. It should display the label “Total Orders (Email)” in the Orders table:
add_filter( 'manage_edit-shop_order_columns', 'ecommercehints_add_order_count_column', 20 );
function ecommercehints_add_order_count_column( $columns ) {
$columns['email_order_count'] = __( 'Totale Ordini (Email)', 'woocommerce' );
return $columns;
}
// Populate column with order count
add_action( 'manage_shop_order_posts_custom_column', 'ecommercehints_populate_new_column' );
function ecommercehints_populate_new_column( $column ) {
global $post;
if ( 'email_order_count' === $column ) {
$billing_email = get_post_meta( $post->ID, '_billing_email', true );
if ( $billing_email ) {
$customer_orders = get_posts( array(
'numberposts' => -1,
'meta_key' => '_billing_email',
'meta_value' => $billing_email,
'post_type' => wc_get_order_types(),
'post_status' => array_keys( wc_get_order_statuses() ),
) );
$order_count = count( $customer_orders );
echo $order_count;
}
}
}Problem Description:
- The column does not appear in the WooCommerce Orders table.
- The column is not visible under the Screen Options to enable/disable it.
- Before switching to HPOS, the column was displaying correctly with the same code.
- I tried enabling WordPress debugging (
WP_DEBUG
,WP_DEBUG_LOG
), but no logs are generated, which suggests the hook might not be firing.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- You must be logged in to reply to this topic.