Tell us what you are trying to do?
I am in the process of customizing my woocommerce customer-completed-order.php email template by replacing the default email template with my own in my child theme. I've managed to write a function in functions.php that injects a table containing data from the Product rather than the Order.
Its working except for 2 issues:
1. I have been unable to successfully render the Display text rather than the value of the custom field:
add_action( 'woocommerce_email_after_order_table', 'jh_add_content_specific_email', 20, 4 );
function jh_add_content_specific_email( $order, $sent_to_admin, $plain_text, $email ) {
// Get the product ID of the current order and assign to variable $product_id
foreach ( $order->get_items() as $item ) {
$product_id = $item->get_product_id();
} ?>
<h2>Your Sponsored Family Details</h2>
<!-- BEGIN Family Details Table -->
<div style="margin-bottom: 40px;">
<table class="td" cellspacing="0" cellpadding="6" style="width: 100%; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif;" border="1">
<thead>
<tr>
<th class="td" scope="col" style="">Child Gender</th>
<th class="td" scope="col" style="">Child Age</th>
<th class="td" scope="col" style="">Gift Suggestion</th>
</tr>
</thead>
<tbody>
<tr>
<td><?php echo get_post_meta( $product_id, 'wpcf-_child-1-gender', true ); ?></td>
<td><?php echo get_post_meta( $product_id, 'wpcf-_child-1-age', true ); ?></td>
<td><?php echo get_post_meta( $product_id, 'wpcf-_child-1-gift', true ); ?></td>
</tr>
<tr>
<td><?php echo get_post_meta( $product_id, 'wpcf-_child-2-gender', true ); ?></td>
<td><?php echo get_post_meta( $product_id, 'wpcf-_child-2-age', true ); ?></td>
<td><?php echo get_post_meta( $product_id, 'wpcf-_child-2-gift', true ); ?></td>
</tr>
<tr>
<td><?php echo get_post_meta( $product_id, 'wpcf-_child-3-gender', true ); ?></td>
<td><?php echo get_post_meta( $product_id, 'wpcf-_child-3-age', true ); ?></td>
<td><?php echo get_post_meta( $product_id, 'wpcf-_child-3-gift', true ); ?></td>
</tr>
.... etc etc etc... up to 6 children
</tbody>
<tfoot>
</tfoot>
</table>
</div>
<!-- END Family Details Table -->
<?php }
In the first <td> what renders in the email is the raw value but I'd like it to be the Display Text instead.
I tried this but it did not work (Im sure its wrong):
<td><?php echo types_render_field( 'wpcf-_child-1-gender', array( 'id' => $product_id )); ?></td>
(My goal here is to communicate to the Sponsor that sponsored the Family the child information so that the Sponsor can buy the Christmas presents. This data is in Product custom fields, not in Order custom fields )
2. This table displays from 1 to 6 children, depending on how many children are in the Product. I'd like to only display rows of child data if that data exists rather than show all 6 rows even though 2 through 6 may be empty
The children are NOT a repeating field. I have 6 sets of sets of 3 fields each:
Child 1: age, gender, gift
Child 2: age, gender, gift
Child 3: age, gender, gift
etc
etc
So I need a conditional but I am not sure how to write the php for it to work in a function that renders in an email.
Is there any documentation that you are following?
Too many sources to list them all
What is the link to your site?
hidden link
thank you