Support » Plugin: WooCommerce » 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..)

    [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)
  • 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.

    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.