checkout editor code

Custom Email Subject Placeholders Woocommerce New Order Email using Checkout Editor

I built a website with woocommerce for a local children’s football club. They sold kit and memberships. For each new order they wanted the email subject (woocommerce new order email) to have the child’s first and last name, the team and a list of products they bought. We used the Woocommerce checkout editor plugin (ThemeHigh). We added lots of extra fields to the checkout page like age, child’s name, team etc. It was some of these fields we wanted to show in the subject.  I won’t explain the code as I don’t understand it but I found something online (for one new placeholder)  then asked the plugin support (ThemeHigh) and they modified it for me. Here is the result (below). If you have Woocommerce checkout editor just replace child_name, childlastname, team with your field names that you want to put in. Also add the appropriate placeholders in Woocommerce -> Settings -> Email -> New Order email.

For me I put in the subject area

{child_name} {childlastname} {team} | {product_name}

Put this below in functions.php or use a plugin or child theme. I use My custom functions.

add_filter( 'woocommerce_email_format_string' , 'filter_email_format_string', 20, 2 );
function filter_email_format_string( $string, $email ) {
    // Get the instance of the WC_Order object
    $order = $email->object;
    $products_names = array();
    // Loop through order items
    foreach( $order->get_items() as $item ) {
        $products_names[] = $item->get_name();
    // Additional wanted placeholders in the array of find / relace pairs
    $additional_placeholders = array(
        '{child_name}'      => $order->get_meta('child_name'),
        '{childlastname}'   => $order->get_meta('childlastname'),
        '{team}'   => $order->get_meta('team'), // <=== HERE
        '{product_name}'	=> implode(', ', $products_names),
    // return the clean string with new replacements
    return str_replace( array_keys( $additional_placeholders ), array_values( $additional_placeholders ), $string );