I am using Woocommerce for registration for classes; each class/product has up to 20 custom fields, which I need to return as variables in order to highly customize the checkout and order details pages and customer email template.
I don't just want to add all of the custom meta data with hooks, because I need very tight control over the output. For instance, the following answer worked fine for including custom fields in the cart page: Display Custom Field's Value in Woocommerce Cart & Checkout items
But I would like them in checkout, order details and emails as well, with full control over the HTML where they appear (in some cases they will need to be converted as well, e.g., Unix timestamps to human readable time).
In order-item-details.php
template I have tried the following:
$room = get_post_meta( $product->ID, 'room', true );
$room_number = get_post_meta( $product->ID, 'room_number', true );
$instructor = get_post_meta( $product->ID, 'instructor', true );
echo 'Your instructor is ' . $instructor . '.';
echo 'Your class is in ' . $room . '.';
But it didn't work…
How can I access and use custom field values associated with a specific product?