Title: Adding fields
Last modified: August 22, 2016

---

# Adding fields

 *  Resolved [hanneslf](https://wordpress.org/support/users/hanneslf/)
 * (@hanneslf)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/adding-fields-4/)
 * Hi Ankit,
    I am trying to add fields to the csv file. I can do it using the way
   che_idan suggested b;y editing the plugin directly. But I was hoping to do it
   in the funtions.php file with the wpg_order_columns and wpg_before_csv_write 
   hooks but can’t seem to get it to work.
 * Would you have an example of this. This was my attempt.
 *     ```
       function extra_order_columns($cols) {
       	$cols['wc_settings_tab_customer_address'] = '__( "Address", "woocommerce-simply-order-export" )';
       	return $cols;
       }
       add_filter( 'wpg_order_columns' , 'extra_order_columns' );
   
       function extra_order_columns_data($csv_values) {
       	array_push( $csv_values, self::customer_meta( get_the_ID(), '_billing_address_1' ) );
       	return $csv_values;
       }
       add_filter( 'wpg_before_csv_write' , 'extra_order_columns_data' );
       ```
   
 * [https://wordpress.org/plugins/woocommerce-simply-order-export/](https://wordpress.org/plugins/woocommerce-simply-order-export/)

Viewing 15 replies - 1 through 15 (of 37 total)

1 [2](https://wordpress.org/support/topic/adding-fields-4/page/2/?output_format=md)
[3](https://wordpress.org/support/topic/adding-fields-4/page/3/?output_format=md)
[→](https://wordpress.org/support/topic/adding-fields-4/page/2/?output_format=md)

 *  [ankitgadertcampcom](https://wordpress.org/support/users/ankitgadertcampcom/)
 * (@ankitgadertcampcom)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/adding-fields-4/#post-5771218)
 * Hi hanneslf,
 * Please follow these steps. In below example I am adding payment method field.
 * Step 1: Add field to column
 *     ```
       function wpg_add_columns($cols) {
   
       	$cols['wc_settings_tab_payment_method'] = __('Payment Method', 'mytheme');
       	return $cols;
       }
       add_filter('wpg_order_columns', 'wpg_add_columns');
       ```
   
 * Step 2: Add same column to settings, so that it will appear in settings page.
 *     ```
       function wpg_add_fields($settings) {
   
       	$settings['payment_method'] = array(
       								'name' => __( 'Payment Method', 'woocommerce-simply-order-export' ),
       								'type' => 'checkbox',
       								'desc' => __( 'Payment Method', 'woocommerce-simply-order-export' ),
       								'id'   => 'wc_settings_tab_payment_method'
       							);
   
       	return $settings;
   
       }
       add_filter('wc_settings_tab_order_export', 'wpg_add_fields');
       ```
   
 * **Note:** Notice that in above step, id attribute is identical to that of array
   key in step 1. ( wc_settings_tab_payment_method )
 * Step 3: Add it to csv.
 *     ```
       function csv_write( &$csv, $od, $fields ) {
   
       	if( !empty( $fields['wc_settings_tab_payment_method'] ) && $fields['wc_settings_tab_payment_method'] === true ){
       		$payment_method = get_post_meta( $od->id, '_payment_method_title', true );
       		array_push( $csv, $payment_method );
       	}
   
       }
       add_action('wpg_before_csv_write', 'csv_write', 10, 3);
       ```
   
 * In these 3 steps you can add as many fields you want to add.
 * Let me know if you have any further query.
 *  [helvik](https://wordpress.org/support/users/helvik/)
 * (@helvik)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/adding-fields-4/#post-5771253)
 * will this work for custom fields as well? I added a field new_field after the
   order notes section and need to pull that into the export? Show a quick example?
 *  [ankitgadertcampcom](https://wordpress.org/support/users/ankitgadertcampcom/)
 * (@ankitgadertcampcom)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/adding-fields-4/#post-5771260)
 * This will also work for custom fields.
    Just replace `get_post_meta( $od->id,'
   _payment_method_title', true );`
 * with your meta_key. That’s it.
 *  Thread Starter [hanneslf](https://wordpress.org/support/users/hanneslf/)
 * (@hanneslf)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/adding-fields-4/#post-5771265)
 * Brilliant Ankit.
    Thanks for this plugin. Hannes
 *  [torcat](https://wordpress.org/support/users/torcat/)
 * (@torcat)
 * [11 years ago](https://wordpress.org/support/topic/adding-fields-4/#post-5771403)
 * Hi
 * I have added what here its writed for payment metode, and not show in the csv
 * in the csv exported only the customer name, amount, phone number
 * what I did not do well?
 *  [ankitgadertcampcom](https://wordpress.org/support/users/ankitgadertcampcom/)
 * (@ankitgadertcampcom)
 * [11 years ago](https://wordpress.org/support/topic/adding-fields-4/#post-5771404)
 * Hi,
 * Have you checked those fields and saved ? Only after saving those settings, it
   will be possible to extract that field in CSV.
 * Let me know your response.
 * Regards
 *  [Swissmiss85](https://wordpress.org/support/users/swissmiss85/)
 * (@swissmiss85)
 * [11 years ago](https://wordpress.org/support/topic/adding-fields-4/#post-5771405)
 * Hi
 * Thanks for the great plugin! Everything works fine but I’m not sure how to add
   more than one field. Could you be so kind and give me an example of the above
   code when adding more than one field.
 * Thanks so much!
 *  [ankitgadertcampcom](https://wordpress.org/support/users/ankitgadertcampcom/)
 * (@ankitgadertcampcom)
 * [11 years ago](https://wordpress.org/support/topic/adding-fields-4/#post-5771406)
 * Hi,
 * I am currently working on developing a field manager pack for this plugin. It
   will be basically an add-on for this plugin which will have cluster of fields.
   I think this should be ready soon, I will let you know once it will be available.
 * Thank you
 *  [Swissmiss85](https://wordpress.org/support/users/swissmiss85/)
 * (@swissmiss85)
 * [11 years ago](https://wordpress.org/support/topic/adding-fields-4/#post-5771407)
 * Thanks for your response. I’m looking forward to this add-on.
 *  [MC-land](https://wordpress.org/support/users/michaeliresource/)
 * (@michaeliresource)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/adding-fields-4/#post-5771421)
 * can I see an example of the functions.php file code which has more than 1 custom
   field to it?
 *  [Jean LeSheep](https://wordpress.org/support/users/cyarema/)
 * (@cyarema)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/adding-fields-4/#post-5771422)
 * Do you just keep repeating the three steps? I feel like there would be an array
   you would keep everything together.
 *  [Dillx](https://wordpress.org/support/users/dillx/)
 * (@dillx)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/adding-fields-4/#post-5771423)
 * I ‘ve managed to get two extra fields on the admin screen but cant get them written
   to the csv file. It just ignores them.
    The code worked when I only had one.
 *  [Dillx](https://wordpress.org/support/users/dillx/)
 * (@dillx)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/adding-fields-4/#post-5771424)
 * function xxxx_Woo_export_csv_write( &$csv, $od, $fields ) {
 *  if( !empty( $fields[‘wc_settings_findus_method’] ) && $fields[‘wc_settings_findus_method’]
   === true ){
    $findus_method = get_post_meta( $od->id, ‘How did you find us’, 
   true ); array_push( $csv, $findus_method ); };
 *  if( !empty( $fields[‘wc_settings_order_id’] ) && $fields[‘wc_settings_order_id’]
   === true ){
    array_push( $csv, $od->id ); };
 * }
    add_action(‘wpg_before_csv_write’, ‘xxxx_Woo_export_csv_write’, 10, 3);
 *  [Dillx](https://wordpress.org/support/users/dillx/)
 * (@dillx)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/adding-fields-4/#post-5771425)
 * This is an example of adding two fields.
    /** * Add columns to WooCommerce Simply
   Order Export */
 * function f14a_Woo_export_add_col($cols) {
 *  $cols[‘wc_settings_findus_method’] = __(‘How Did You Find Us’, ‘mytheme’);
    
   $cols[‘wc_settings_order_id’] = __(‘Order Id’, ‘mytheme’); return $cols; } add_filter(‘
   wpg_order_columns’, ‘f14a_Woo_export_add_col’);
 * /**
    * Add columns to WooCommerce Simply Order Export – settings page * Notice
   that in above step, id attribute is identical to that of array key in step 1 */
   function f14a_Woo_export_add_fields($settings) {
 *  $settings[‘findus_method’] = array(
    ‘name’ => __( ‘How Did You Find Us’, ‘woocommerce-
   simply-order-export’ ), ‘type’ => ‘checkbox’, ‘desc’ => __( ‘How Did You Find
   Us’, ‘woocommerce-simply-order-export’ ), ‘id’ => ‘wc_settings_findus_method’);
 *  $settings[‘order_id’] = array(
    ‘name’ => __( ‘Order Id’, ‘woocommerce-simply-
   order-export’ ), ‘type’ => ‘checkbox’, ‘desc’ => __( ‘Order Id’, ‘woocommerce-
   simply-order-export’ ), ‘id’ => ‘wc_settings_order_id’ ); return $settings;
 * }
    add_filter(‘wc_settings_tab_order_export’, ‘f14a_Woo_export_add_fields’);
 * /**
    * Add columns to WooCommerce Simply Order Export – add to csv */ function
   f14a_Woo_export_csv_write( &$csv, $od, $fields ) {
 *  if( !empty( $fields[‘wc_settings_findus_method’] ) && $fields[‘wc_settings_findus_method’]
   === true ){
    $findus_method = get_post_meta( $od->id, ‘How did you find us’, 
   true ); array_push( $csv, $findus_method ); }; if( !empty( $fields[‘wc_settings_order_id’])&&
   $fields[‘wc_settings_order_id’] === true ){ array_push( $csv, $od->id ); };
 * }
    add_action(‘wpg_before_csv_write’, ‘f14a_Woo_export_csv_write’, 10, 3);
 *  [ankitgadertcampcom](https://wordpress.org/support/users/ankitgadertcampcom/)
 * (@ankitgadertcampcom)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/adding-fields-4/#post-5771426)
 * Thank you Dillx for your cooperation 🙂

Viewing 15 replies - 1 through 15 (of 37 total)

1 [2](https://wordpress.org/support/topic/adding-fields-4/page/2/?output_format=md)
[3](https://wordpress.org/support/topic/adding-fields-4/page/3/?output_format=md)
[→](https://wordpress.org/support/topic/adding-fields-4/page/2/?output_format=md)

The topic ‘Adding fields’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/woocommerce-simply-order-export_339898.
   svg)
 * [WooCommerce Simply Order Export](https://wordpress.org/plugins/woocommerce-simply-order-export/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce-simply-order-export/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce-simply-order-export/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce-simply-order-export/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce-simply-order-export/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce-simply-order-export/reviews/)

## Tags

 * [extra fields](https://wordpress.org/support/topic-tag/extra-fields/)

 * 37 replies
 * 14 participants
 * Last reply from: [Marie Comet](https://wordpress.org/support/users/chaton666/)
 * Last activity: [10 years, 3 months ago](https://wordpress.org/support/topic/adding-fields-4/page/3/#post-5771464)
 * Status: resolved