Title: Add another field?
Last modified: August 21, 2016

---

# Add another field?

 *  Resolved [jeremyomeara](https://wordpress.org/support/users/jeremyomeara/)
 * (@jeremyomeara)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/add-another-field/)
 * Hi there. Great little plugin guys, thank you. Id REALLY like to, however, be
   able to add another field. My current setup is that I have an opt-in on the checkout
   page, which adds users to the birthday mailing list, however it’d be great to
   be able to add a field for birth dates. Is this possible?
 * [https://wordpress.org/plugins/woocommerce-mailchimp/](https://wordpress.org/plugins/woocommerce-mailchimp/)

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

 *  Plugin Author [Adam Anderly](https://wordpress.org/support/users/anderly/)
 * (@anderly)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/add-another-field/#post-4661792)
 * While this isn’t possible via the UI, this is possible with a little custom code
   that you could drop in functions.php:
 * I’ll try to put together an example and post it here for you to try out.
 *  Thread Starter [jeremyomeara](https://wordpress.org/support/users/jeremyomeara/)
 * (@jeremyomeara)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/add-another-field/#post-4661806)
 * That’d be great! Looking forward to seeing it
 *  Plugin Author [Adam Anderly](https://wordpress.org/support/users/anderly/)
 * (@anderly)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/add-another-field/#post-4661868)
 * [@jeremyomeara](https://wordpress.org/support/users/jeremyomeara/),
 * Sorry for the delay in getting this out. I just published version 1.3 of the 
   plugin which was needed before I could send you a code sample.
 * This should do it:
 *     ```
       // First we add the new birthday field to the checkout fields
       function ss_wc_add_birthday_field( $checkout_fields ) {
   
       	$opt_in_checkbox_display_location = 'billing';
   
       	$field_id = 'birthday';
       	$field_name = __( 'Birthday', 'ss_wc_mailchimp' );
   
       	$checkout_fields[$opt_in_checkbox_display_location][$field_id] = array(
       		'type'    => 'text',
       		'label'   => esc_attr( $field_name ),
       		'placeholder' => 'mm/dd'
       	);
   
       	return $checkout_fields;
       }
       add_filter( 'woocommerce_checkout_fields', 'ss_wc_add_birthday_field' );
   
       // Make birthday a date picker mm/dd field
       function ss_wc_add_checkout_field_datepicker() {
           if ( is_checkout() ) {
               $js = 'jQuery( "#birthday" ).css("width","125px").datepicker({ changeMonth: true, changeYear: true, yearRange:"-100:+0", dateFormat: "mm/dd" });';
               // Check if WC 2.1+
               if ( defined( 'WC_VERSION' ) && WC_VERSION ) {
                   wc_enqueue_js( $js );
               } else {
                   global $woocommerce;
                   $woocommerce->add_inline_js( $js );
               }
           }
       }
       add_filter( 'wp_footer' , 'ss_wc_add_checkout_field_datepicker' );
   
       // Save the birthday field with the order
       function ss_wc_save_birthday_field( $order_id ) {
       	$birthday = isset( $_POST['birthday'] ) ? $_POST['birthday'] : null;
       	update_post_meta( $order_id, 'birthday', $birthday );
       }
       add_action( 'woocommerce_checkout_update_order_meta', 'ss_wc_save_birthday_field' );
   
       // tie into the WooCommerce MailChimp 'ss_wc_mailchimp_subscribe_merge_vars' action filter to add the MailChimp merge var for Birthday
       function ss_wc_send_birthday_field_to_mailchimp( $order_id, $merge_vars ) {
           // retrieve the birthday from the order meta/custom fields
           $birthday = get_post_meta( $order_id, 'birthday', true );
   
           // Add 'BIRTHDAY' merge variable to MailChimp call (change 'BIRTHDAY' to whatever your merge variable is called in MailChimp)
       	$merge_vars['BIRTHDAY'] = $birthday;
           return $merge_vars;
       }
       add_filter( 'ss_wc_mailchimp_subscribe_merge_vars' , 'ss_wc_send_birthday_field_to_mailchimp', 10 , 2 );
       ```
   
 * _[Moderator Note: Please post code & markup between backticks or use the code
   button. Your posted code may now have been permanently damaged by the forum’s
   parser.]_
 *  Thread Starter [jeremyomeara](https://wordpress.org/support/users/jeremyomeara/)
 * (@jeremyomeara)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/add-another-field/#post-4661871)
 * Hi there Anderly. Thanks for that mate, it’s showing the new birthday field fine
   and the subscription itself is working great, but it just wont pass the birthday
   information to MC properly. Any ideas?
 *  Plugin Author [Adam Anderly](https://wordpress.org/support/users/anderly/)
 * (@anderly)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/add-another-field/#post-4661898)
 * Please use this updated code instead of that above. The above code had the filter
   function parameters in the wrong order.
 *     ```
       // First we add the new birthday field to the checkout fields
       function ss_wc_add_birthday_field( $checkout_fields ) {
   
       	$opt_in_checkbox_display_location = 'billing';
   
       	$field_id = 'birthday';
       	$field_name = __( 'Birthday', 'ss_wc_mailchimp' );
   
       	$checkout_fields[$opt_in_checkbox_display_location][$field_id] = array(
       		'type'    => 'text',
       		'label'   => esc_attr( $field_name ),
       		'placeholder' => 'mm/dd'
       	);
   
       	return $checkout_fields;
       }
       add_filter( 'woocommerce_checkout_fields', 'ss_wc_add_birthday_field' );
   
       // Make birthday a date picker mm/dd field
       function ss_wc_add_checkout_field_datepicker() {
           if ( is_checkout() ) {
               $js = 'jQuery( "#birthday" ).css("width","125px").datepicker({ changeMonth: true, changeYear: true, yearRange:"-100:+0", dateFormat: "mm/dd" });';
               // Check if WC 2.1+
               if ( defined( 'WC_VERSION' ) && WC_VERSION ) {
                   wc_enqueue_js( $js );
               } else {
                   global $woocommerce;
                   $woocommerce->add_inline_js( $js );
               }
           }
       }
       add_filter( 'wp_footer' , 'ss_wc_add_checkout_field_datepicker' );
   
       // Save the birthday field with the order
       function ss_wc_save_birthday_field( $order_id ) {
       	$birthday = isset( $_POST['birthday'] ) ? $_POST['birthday'] : null;
       	update_post_meta( $order_id, 'birthday', $birthday );
       }
       add_action( 'woocommerce_checkout_update_order_meta', 'ss_wc_save_birthday_field' );
   
       // tie into the WooCommerce MailChimp 'ss_wc_mailchimp_subscribe_merge_vars' action filter to add the MailChimp merge var for Birthday
       function ss_wc_send_birthday_field_to_mailchimp( $merge_vars, $order_id ) {
           // retrieve the birthday from the order meta/custom fields
           $birthday = get_post_meta( $order_id, 'birthday', true );
   
           // Add 'BIRTHDAY' merge variable to MailChimp call (change 'BIRTHDAY' to whatever your merge variable is called in MailChimp)
       	$merge_vars['BIRTHDAY'] = $birthday;
           return $merge_vars;
       }
       add_filter( 'ss_wc_mailchimp_subscribe_merge_vars' , 'ss_wc_send_birthday_field_to_mailchimp', 10 , 2 );
       ```
   
 *  [CarolineElisa](https://wordpress.org/support/users/carolineelisa/)
 * (@carolineelisa)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/add-another-field/#post-4661900)
 * Thanks for updating the code anderly but the birthday value is still not getting
   passed for me. I can see the following in the debug.log:
 *     ```
       [vars] => Array
               (
                   [FNAME] => Caroline Elisa
                   [LNAME] => Haggerty
   
                   [BDAY] => 18/08/1980
               )
       ```
   
 * In Mailchimp, BDAY is the merge tag, I’ve also tried with MERGE4:
    [http://monosnap.com/image/Ann6AwvufzUlDZRL4YtNycnzt6pIT5](http://monosnap.com/image/Ann6AwvufzUlDZRL4YtNycnzt6pIT5)
 *  Plugin Author [Adam Anderly](https://wordpress.org/support/users/anderly/)
 * (@anderly)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/add-another-field/#post-4661901)
 * Are you getting an error in the log? Also, what data type do you have BDAY set
   to in MailChimp?
 *  [CarolineElisa](https://wordpress.org/support/users/carolineelisa/)
 * (@carolineelisa)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/add-another-field/#post-4661902)
 * There is no error message and the subscriber is being created on order creation.
   The full output is:
 *     ```
       [18-Feb-2015 01:53:10 UTC] Order Opt-In Value: ''
       [18-Feb-2015 01:53:10 UTC] Subscribe customer (~@gmail.com) to list cd042f4bc3
       [18-Feb-2015 01:53:10 UTC] Calling MailChimp API listSubscribe method with the following: Array
       (
           [listid] => cd042f4bc3
           [email] => ~@gmail.com
           [vars] => Array
               (
                   [FNAME] => Caroline Elisa
                   [LNAME] => Haggerty
                   [GROUPINGS] => Array
                       (
                           [0] => Array
                               (
                                   [name] => Groups
                                   [groups] => Customer
                               )
   
                       )
   
                   [BDAY] => 18/08/1980
               )
   
           [email_type] => html
           [double_optin] => 1
           [update_existing] => 1
           [replace_interests] =>
           [send_welcome] =>
       )
   
       [18-Feb-2015 01:53:11 UTC] MailChimp API response: %s
       ```
   
 * The field is a date field in Mailchimp (to include the year). Here are the settings:
   [http://monosnap.com/image/Ann6AwvufzUlDZRL4YtNycnzt6pIT5](http://monosnap.com/image/Ann6AwvufzUlDZRL4YtNycnzt6pIT5)
 * And here is the sign up form URL: [http://eepurl.com/8Lqin](http://eepurl.com/8Lqin)

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

The topic ‘Add another field?’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce-mailchimp/assets/icon.svg?rev=1495270)
 * [WP WooCommerce Mailchimp](https://wordpress.org/plugins/woocommerce-mailchimp/)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce-mailchimp/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce-mailchimp/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce-mailchimp/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce-mailchimp/reviews/)

 * 8 replies
 * 3 participants
 * Last reply from: [CarolineElisa](https://wordpress.org/support/users/carolineelisa/)
 * Last activity: [11 years, 2 months ago](https://wordpress.org/support/topic/add-another-field/#post-4661902)
 * Status: resolved