Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author acowebs

    (@acowebs)

    It is possible to show the product addon data in order listing table with custom code. Please find an example code below, where you can change the parameters as per your needs

    
    add_filter( 'manage_edit-shop_order_columns', 'register_is_first_order_column', 10, 1 );
    function register_is_first_order_column( $columns ) {
        $columns['_custom_items'] = 'Number';
        return $columns;
    }
    
    add_action( 'manage_shop_order_posts_custom_column', 'display_is_first_order_column', 10, 1 );
    function display_is_first_order_column( $column ) {
        global $post;
        if ( '_custom_items' === $column ) {
            $order_id = $post->ID;
            $order = wc_get_order( $order_id );
            foreach( $order->get_items(  ) as $item_id => $item ) {
                echo "<p><b>Item:</b> ".$item->get_name()."</p>";
                $meta_data = $item->get_formatted_meta_data('');
                foreach ( $meta_data as $meta_id => $meta ) {
                    $field_display_label = wp_kses_post( $meta->display_key );
                    if($field_display_label=="Date Field"){ // change this label with the data you want to show
                        echo "<div style='display:inline-flex;'><p><b>Date:</b> </p>".$meta->display_value."</div>";
                    }
                }
            }
    
        }
    }
    Thread Starter slckv

    (@slckv)

    Thank you so much! Great! It worked like a charm.

    One last thing, is there any way to make them sortable on the Orders page again? Is that possible?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Post Number field data to Orders table’ is closed to new replies.