Title: woocommerce mail php code doubt
Last modified: August 20, 2016

---

# woocommerce mail php code doubt

 *  [abc3495](https://wordpress.org/support/users/abc3495/)
 * (@abc3495)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/woocommerce-mail-php-code-doubt/)
 * Hi,
 * I have a doubt on a code which is working for me perfectly.. Iam not asking you
   guyz to write or edit code, BUT i just had a little doubt from the below exisitng
   code: (I found below in some threads..)
 *     ```
       * Adding the Custom field to the checkout
        **/
       add_action('woocommerce_after_order_notes', 'my_custom_checkout_field');
   
       function my_custom_checkout_field( $checkout ) {
   
       global $woocommerce;
       $found = false;
       //check if product already in cart
   
       	if ( sizeof( $woocommerce->cart->get_cart() ) > 0 ) {
   
       			foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values ) {				
   
       				$_product = $values['data'];
   
       				if ( $_product->id == 209) {
   
       					echo '<div id="my_custom_checkout_field"><h3>'.__('My Field').'</h3>';
       					woocommerce_form_field( 'my_field_name', array(
       						'type' 			=> 'checkbox',
       						'class' 		=> array('my-field-class form-row-wide'),
       						'label' 		=> __('Fill in this field'),
       						'placeholder' 	=> __('Enter a number'),
       						), $checkout->get_value( 'my_field_name' ));
   
       					echo '</div>';
   
       				  echo '<div id="my_custom_checkout_field2"><h3>'.__('Keywords').'</h3>';
   
       				    woocommerce_form_field( 'enter_keywords', array(
       					'type'          => 'text',
       					'required'  => true,
       					'class'         => array('my-field-class form-row-wide'),
       					'label'         => __('Enter Keywords'),
       					'placeholder'       => __('Enter something'),
       					), $checkout->get_value( 'keywords' ));
   
       				    echo '</div>';
       				}
   
       			}
   
       		}
   
       }
       ```
   
 *     ```
       /**
        * 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';
       	$keys[] = 'Keywords';
       	return $keys;
       }
   
       My Doubt is: 
   
       why should I give values for $keys[] as:
       ```
   
 * $keys[] = ‘My Field’;
    $keys[] = ‘Keywords’; ` why cannot I give my_field_name,
   keywords as a values for $keys[]??
 * Please kindly clear me someone, (iam not a php coder..)
 * [http://wordpress.org/extend/plugins/woocommerce/](http://wordpress.org/extend/plugins/woocommerce/)
 * _[Moderator Note: Please post code or markup snippets between backticks or use
   the code button. As it stands, your posted code may now have been permanently
   damaged/corrupted by the forum’s parser.]_

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [bheadrick](https://wordpress.org/support/users/bheadrick/)
 * (@bheadrick)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/woocommerce-mail-php-code-doubt/#post-3239100)
 * yeah, my_field_name would be the meta key, so that code there is probably wrong.
   The first set to display the fields in the checkout is correct, though.
 * I haven’t tested it, though.
 *  Thread Starter [abc3495](https://wordpress.org/support/users/abc3495/)
 * (@abc3495)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/woocommerce-mail-php-code-doubt/#post-3239103)
 * Actually code is working for me perfectly… iam getting mail perfectly! BUT didnt
   understood by looking what, we have to keep values for $keys[] as:
 * $keys[] = ‘My Field’;
    $keys[] = ‘Keywords’;

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘woocommerce mail php code doubt’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce/assets/icon.svg?rev=3234504)
 * [WooCommerce](https://wordpress.org/plugins/woocommerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce/reviews/)

## Tags

 * [email](https://wordpress.org/support/topic-tag/email/)
 * [mail](https://wordpress.org/support/topic-tag/mail/)

 * 2 replies
 * 2 participants
 * Last reply from: [abc3495](https://wordpress.org/support/users/abc3495/)
 * Last activity: [13 years, 5 months ago](https://wordpress.org/support/topic/woocommerce-mail-php-code-doubt/#post-3239103)
 * Status: not resolved