Add custom fields to New Order emails
-
Hi,
Ive added 2 fields to the Checkout page (Card Message and Preferred Date of Delivery). This is all working fine, but the 2 fields are not being included in the New Order email to the client.The code I have so far is:
// ADD Custom Fields to Checkout Page /** * Add the field to the checkout **/ add_action('woocommerce_after_order_notes', 'my_custom_checkout_field'); function my_custom_checkout_field( $checkout ) { // card message $cardoptions = array('' => __('Select CardMessage', 'woocommerce' )); echo '<div id="my_custom_checkout_field"><h3>'.__('Card message').'</h3>'; woocommerce_form_field( 'card_message', array( 'type' => 'textarea', 'class' => array('my-field-class form-row-wide'), 'id' => 'card_message', 'required' => true, 'label' => __('Enter your message to appear on the card'), 'placeholder' => __(''), 'options' => $cardoptions ),$checkout->get_value( 'card_message' )); echo '</div>'; // select delivery date $mydateoptions = array('' => __('Select DeliveryDay', 'woocommerce' )); echo '<div id="my_custom_checkout_field"><h3>'.__('Delivery date').'</h3>'; woocommerce_form_field( 'order_delivery_date', array( 'type' => 'text', 'class' => array('my-field-class form-row-wide'), 'id' => 'datepicker', 'required' => true, 'label' => __('We deliver Mon to Sat. Any orders received on a Sunday will be delivered on the next working day'), 'placeholder' => __('Select Date'), 'options' => $mydateoptions ),$checkout->get_value( 'order_delivery_date' )); echo '</div>'; } /** * Process the checkout **/ add_action('woocommerce_checkout_process', 'my_custom_checkout_field_process'); function my_custom_checkout_field_process() { global $woocommerce; // Check if set, if its not set add an error. if (!$_POST['card_message']) wc_add_notice( '<strong>CardMessage</strong> ' . __( 'is a required field.', 'woocommerce' ), 'error' ); if (!$_POST['order_delivery_date']) wc_add_notice( '<strong>DeliveryDay</strong> ' . __( 'is a required field.', 'woocommerce' ), 'error' ); } /** * Update the order meta with field value **/ add_action('woocommerce_checkout_update_order_meta', 'my_custom_checkout_field_update_order_meta'); function my_custom_checkout_field_update_order_meta( $order_id ) { if ($_POST['card_message']) update_post_meta( $order_id, 'CardMessage', esc_attr($_POST['card_message'])); if ($_POST['order_delivery_date']) update_post_meta( $order_id, 'DeliveryDay', esc_attr($_POST['order_delivery_date'])); }
What do I need to add so that the 2 new fields are included on the New Order and Failed Order emails?
Thanks
Viewing 12 replies - 1 through 12 (of 12 total)
Viewing 12 replies - 1 through 12 (of 12 total)
- The topic ‘Add custom fields to New Order emails’ is closed to new replies.