php - Display in WooCommerce thankyou a custom field value based on a custom table

one text

Solution:

There are some mistakes in your code… Use the following instead:

add_action( 'woocommerce_thankyou_order_received_text', 'additional_note_order_data_in_admin', 10, 1    );
function additional_note_order_data_in_admin( $order_received_text, $order ){
    global $wpdb;

    $order_id = $order->get_id(); // Get order Id (For info, If needed)

    $results = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}woocommerce_custom_fields");

    if ( ! empty($results) ) {
        foreach ( $results as $result ) {
            if ( $meta_value = $order->get_meta( '_'.$result->name ) ) {
                $order_received_text .= '</p><p><strong>' . __('Delivery Date') . ':</strong> ' . $meta_value;
            }
        }
    }
    return $order_received_text;
}

Code goes in functions.php file of the active child theme (or active theme). It should better work.

Source