Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8915189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:55:18+00:00 2026-06-15T04:55:18+00:00

iam using woocommerce plugin… actually this is a php doubt I have.. Iam using

  • 0

iam using woocommerce plugin… actually this is a php doubt I have.. Iam using some custom fields, so i shuld get values of those custom fields into my email..

When Iam using one custom field ‘My Field’ , iam getting value for that to my email, BUT iam not understanding how to get values of all custom fields to my email..

Below is the code that works for single custom field: (from here: https://gist.github.com/3905785 )

/**
 * 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"><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>';
}

/**
 * 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['my_field_name']) update_post_meta( $order_id, 'My Field', esc_attr($_POST['my_field_name']));
}

/**
 * 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;
}

I tried below code for 2 custom fields: (below code not getting any custom field values to my mail.. ) pls tell me what am i doing wrong in below code:

/**
 * 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"><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_field"><h3>'.__('Keywords').'</h3>';

    woocommerce_form_field( 'keywords', array(
        'type'          => 'text',
        'class'         => array('my-field-class form-row-wide'),
        'label'         => __('Fill in this field'),
        'placeholder'       => __('Enter something'),
        ), $checkout->get_value( 'keywords' ));

    echo '</div>';
}

/**
 * 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['my_field_name']) update_post_meta( $order_id, 'My Field', esc_attr($_POST['my_field_name']));

        if ($_POST['keywords']) update_post_meta( $order_id, 'Keywords', esc_attr($_POST['keywords']));
}

/**
 * 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,Keywords';
    return $keys;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T04:55:20+00:00Added an answer on June 15, 2026 at 4:55 am

    First of all the line:

    $keys[] = 'My Field,Keywords';
    

    should be changed to:

    $keys[] = 'My Field';
    $keys[] = 'Keywords';
    

    The code you had was creating one array entry with the string ‘My Field,Keywords’ as opposed to 2 array entries with the strings ‘My Field’ and ‘Keywords’.

    This is definitely one of the causes of the problem.

    It may not be critical but you should change the id of the second div tag – having multiple elements with the same id is not good.

    Make these changes and try again. If there are further problems then we can tackle them in turn.

    I hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi i have a small problem , iam using join to get some names
Iam using c# vs2010. For my windows forms project I have some PNG,Gif,Jpg images
Iam using linq to SQl, And I have some Serilization problem, For Example I
Iam using structure map for resolving my dependencies, however i have a rather special
iam using AVFoundation Framework to play mp3 file ,everything works great ، i have
iam using GET command to get the content of a page.When i write the
Iam using netbeans 6.9 for PHP , the file i was working on corrupted
Iam using the following code in my file for overlay image.This works fine in
iam using jquery and want to do below written //this is a template <div
iam using Asp.Net 2010 and MVC3 framework..I am new to this. When user registers

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.