Add Custom Field to Order Email
-
Hi There,
I make use of the “WooCommerce Checkout Field Editor” plugin which I have created a number of additional fields in.
A field that I use for example is “type_of_event” and “venue_name“.
How can I place these fields into a “new order” email.
The code I have been trying to use is below but not working.
add_filter( 'kadence_woomail_order_body_text', 'custom_function_for_event_type', 10, 2 ); function custom_function_for_event_type( $text, $order ) { if ( is_a( $order, 'WC_Order' ) ) { $text = str_replace( '{event_type}', $order->get_order()->get_meta( 'type_of_event' ), $text ); } return $text; }
Here is the code from the plugin that places the custom fields into the email(s).
/** * Display custom fields in emails */ public function display_custom_fields_in_emails($ofields, $sent_to_admin, $order){ $custom_fields = array(); $fields = THWCFD_Utils::get_checkout_fields(); // Loop through all custom fields to see if it should be added foreach( $fields as $key => $field ) { if(isset($field['show_in_email']) && $field['show_in_email']){ $order_id = THWCFD_Utils::get_order_id($order); $value = get_post_meta( $order_id, $key, true ); if($value){ $label = isset($field['label']) && $field['label'] ? $field['label'] : $key; $label = esc_attr($label); $value = THWCFD_Utils::get_option_text($field, $value); $custom_field = array(); $custom_field['label'] = THWCFD_Utils::t($label); $custom_field['value'] = $value; $custom_fields[$key] = $custom_field; } } } return array_merge($ofields, $custom_fields); }
Many Thanks!
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Add Custom Field to Order Email’ is closed to new replies.