add column in woocommerce order. list FOR (HPOS):

add_filter( 'manage_woocommerce_page_wc-orders_columns',
function( $columns ) {

// Add a custom column for product names
$columns['product_names'] = __( 'Product Names', 'woocommerce' );

return $columns;

}, 20 );

// Display Row Value
add_action( 'manage_woocommerce_page_wc-orders_custom_column',
function( $column, $order_id ) {

// Match Column
if ( 'product_names' === $column ) {
// Get the order object
$order = wc_get_order( $order_id );

// Get items from the order
$items = $order->get_items();

// Initialize an array to store product names
$product_names = array();

// Loop through items and get product names
foreach ( $items as $item ) {
$product_names[] = $item->get_name();
}

// Display product names
echo implode( ', ', $product_names );
}

}, 10, 2 );

Posted

in

by

Tags: