Hi i want to display the information of my custom field on my checkout page to the New Order email in WooCommerce.
This is my Code on function.php
/**
* Add the field to the checkout
*/
add_action( ‘woocommerce_after_order_notes’, ‘my_custom_checkout_field’ );
function my_custom_checkout_field( $checkout ) {
echo ‘<div id=”my_custom_checkout_field”><h2>’ . __(‘My Field’) . ‘</h2>’;
woocommerce_form_field( ‘my_field_name1’, array(
‘type’ => ‘text’,
‘class’ => array(‘my-field-class form-row-wide’),
‘label’ => __(‘Fill in this field’),
‘placeholder’ => __(‘Enter something’),
‘required’ => true,
), $checkout->get_value( ‘my_field_name1’ ));
echo ‘</div>’;
}
/**
* Process the checkout
*/
add_action(‘woocommerce_checkout_process’, ‘my_custom_checkout_field_process’);
function my_custom_checkout_field_process() {
// Check if set, if its not set add an error.
if ( ! $_POST[‘my_field_name1’] )
wc_add_notice( __( ‘Please enter something into this new shiny field.‘ ), ‘error’ );
}
—————————————–
I have tried this code but seems like it doesn’t work.
/**
* Add the field to order emails
**/
add_filter(‘woocommerce_email_order_meta_keys’, ‘my_custom_checkout_field_order_meta_keys’);
function my_custom_checkout_field_order_meta_keys( $keys ) {
$keys[] = ‘My Field’;
return $keys;
}
what wrong with my code ?
Hi sarutty!
That is something outside our support scope, I am afraid, feel free to contact someone from codeable.io, to assist you.
Please do let us know if we can do anything else for you.
Thanks a lot for your patience and understanding
Best regards,
Basilis