• Resolved Tom

    (@tom-van-m)


    Hello team,

    I’m trying to add the custom checkout fields I created in the plugin Custom Checkout Fields to the mailtemplates of Email Template Customizer for WooCommerce
    https://woocommerce.com/document/add-a-custom-field-in-an-order-to-the-emails/ but I don’t get it working.
    I changed the snippet to this:

    /**

    Add a custom field (in an order) to the emails
    */
    add_filter( ‘woocommerce_email_order_meta_fields’, ‘custom_woocommerce_email_order_meta_fields’, 10, 3 );

    function custom_woocommerce_email_order_meta_fields( $fields, $sent_to_admin, $order ) {
    $fields[‘afleveradres_kop’] = array(
    ‘label’ => ( ‘Afleveradres’ ), ‘value’ => get_post_meta( $order->id, ‘afleveradres_kop’, true ), ); return $fields; $fields[‘leverings_adres’] = array( ‘label’ => ( ‘Straat en huisnummer’ ),
    ‘value’ => get_post_meta( $order->id, ‘leverings_adres’, true ),
    );
    return $fields;
    $fields[‘leverings_postcode’] = array(
    ‘label’ => ( ‘Postcode’ ), ‘value’ => get_post_meta( $order->id, ‘leverings_postcode’, true ), ); return $fields; $fields[‘leverings_plaats’] = array( ‘label’ => ( ‘Plaats’ ),
    ‘value’ => get_post_meta( $order->id, ‘leverings_plaats’, true ),
    );
    return $fields;
    $fields[‘contactpersoon_locatie’] = array(
    ‘label’ => ( ‘Naam contactpersoon afleveradres’ ), ‘value’ => get_post_meta( $order->id, ‘contactpersoon_locatie’, true ), ); return $fields; $fields[‘telefoonnummer_leveringsplaats’] = array( ‘label’ => ( ‘Telefoonnummer contactpersoon locatie’ ),
    ‘value’ => get_post_meta( $order->id, ‘telefoonnummer_leveringsplaats’, true ),
    );
    return $fields;
    }

    Any thoughts?

    Best, Tom

    • This topic was modified 1 year, 6 months ago by Tom.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support villasupport

    (@villasupport)

    Hi,

    You need to change your code snippets to the below instead:

    function custom_woocommerce_email_order_meta_fields( $fields, $sent_to_admin, $order ) {
       $fields['afleveradres_kop'] = array(
          'label' => ( 'Afleveradres' ),
          'value' => get_post_meta( $order->id, 'afleveradres_kop', true ),
       );
       $fields['leverings_adres'] = array(
          'label' => ( 'Straat en huisnummer' ),
          'value' => get_post_meta( $order->id, 'leverings_adres', true ),
       );
       $fields['leverings_postcode'] = array(
          'label' => ( 'Postcode' ),
          'value' => get_post_meta( $order->id, 'leverings_postcode', true ),
       );
       $fields['leverings_plaats'] = array(
          'label' => ( 'Plaats' ),
          'value' => get_post_meta( $order->id, 'leverings_plaats', true ),
       );
       
       $fields['contactpersoon_locatie'] = array(
          'label' => ( 'Naam contactpersoon afleveradres' ),
          'value' => get_post_meta( $order->id, 'contactpersoon_locatie', true ),
       );
       $fields['telefoonnummer_leveringsplaats'] = array(
          'label' => ( 'Telefoonnummer contactpersoon locatie' ),
          'value' => get_post_meta( $order->id, 'telefoonnummer_leveringsplaats', true ),
       );
    
       return $fields;
    }

    Then use the WC hook element, choose the order meta hook like this:?https://screencast-o-matic.com/i/crilfEVi1dq save and check again.

    Best regards

    Thread Starter Tom

    (@tom-van-m)

    Hello,

    Thank you so much, that worked great! The fields are now visible in the mails.

    Best,
    Tom

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom Checkout Fields in mails’ is closed to new replies.