• Resolved bgbs

    (@bgbs)


    I’m getting “reguired” errors when submitting order because my email template seems to cause some errors. I don’t know how the two are tied together, but they are.

    Anyways, I’m adding custom checkout fields to the email template using the instructions from here:

    https://docs.woocommerce.com/document/add-a-custom-field-in-an-order-to-the-emails/

    When I add only one field, everything works just fine with order submissions and email template. But when I add second and third checkout fields to email template, errors arise. I want to make sure I’m adding multiple fields properly.

    Right now this is how I add them:

    /**
    * 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[‘about_event’] = array(
    ‘label’ => __( ‘About the Event’ ),
    ‘value’ => get_post_meta( $order->id, ‘about_event’, true ),
    );
    return $fields;
    }`

    function custom_woocommerce_email_order_meta_fields( $fields, $sent_to_admin, $order ) {
    $fields[‘event_number’] = array(
    ‘label’ => __( ‘How many people at the event’ ),
    ‘value’ => get_post_meta( $order->id, ‘event_number’, true ),
    );
    return $fields;
    }`

    function custom_woocommerce_email_order_meta_fields( $fields, $sent_to_admin, $order ) {
    $fields[‘date’] = array(
    ‘label’ => __( ‘Date of the Event’ ),
    ‘value’ => get_post_meta( $order->id, ‘date’, true ),
    );
    return $fields;
    }

    • This topic was modified 3 years, 12 months ago by bgbs.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Nico

    (@nicolamustone)

    Automattic Happiness Engineer

    Hello there,
    The code you are using is wrong. Here is it fixed:

    <?php
    /**
    * 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[‘about_event’] = array(
    		‘label’ => __( ‘About the Event’ ),
    		‘value’ => get_post_meta( $order->id, ‘about_event’, true ),
    	);
    
    	$fields[‘event_number’] = array(
    		‘label’ => __( ‘How many people at the event’ ),
    		‘value’ => get_post_meta( $order->id, ‘event_number’, true ),
    	);
    
    	$fields[‘date’] = array(
    		‘label’ => __( ‘Date of the Event’ ),
    		‘value’ => get_post_meta( $order->id, ‘date’, true ),
    	);
    	
    	return $fields;
    }
    Plugin Support abwaita a11n

    (@abwaita)

    Hi,
    We’ve not heard back from you in a while, so I’m marking this thread as resolved. Hopefully, the above code was helpful!

    If you have further questions, please feel free to open a new topic.

    Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Editing Email Template with Custom Checkout Fields Plugin’ is closed to new replies.